Skip to content

Commit

Permalink
Properly support Loom 1.1 & Gradle 8
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Mar 3, 2023
1 parent 2109738 commit b0a5920
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jar {
attributes 'Implementation-Version': project.version
}

from sourceSets.loom06.output + sourceSets.loom09.output + sourceSets.loom010Legacy.output + sourceSets.loom010.output + sourceSets.loom011.output
from sourceSets.loom06.output + sourceSets.loom09.output + sourceSets.loom010Legacy.output + sourceSets.loom010.output + sourceSets.loom011.output + sourceSets.loom11.output
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package dev.architectury.plugin

import dev.architectury.plugin.loom.LoomInterface
import dev.architectury.plugin.utils.GradleSupport
import dev.architectury.transformer.Transformer
import dev.architectury.transformer.input.OpenedFileAccess
import dev.architectury.transformer.shadowed.impl.com.google.common.hash.Hashing
Expand Down Expand Up @@ -57,7 +58,10 @@ open class ArchitectPluginExtension(val project: Project) {
it.parentFile.mkdirs()
}
}

private val gradle8: Boolean by lazy {
// We use compileOnly on Gradle 8+, I am not sure of the consequences of using compileOnly on Gradle 7

This comment has been minimized.

Copy link
@Juuxel

Juuxel Mar 3, 2023

Member

There shouldn't be any "consequences", it isn't published

This comment has been minimized.

Copy link
@shedaniel

shedaniel Mar 3, 2023

Author Member

Hmm, I was also wondering if arbitrarily adding arch transformer to compileOnly might break some people's setup as they not expect it

GradleSupport.isGradle8(project)
}
private val loom: LoomInterface by lazy {
LoomInterface.get(project)
}
Expand Down Expand Up @@ -136,7 +140,7 @@ open class ArchitectPluginExtension(val project: Project) {

private fun getCompileClasspath(): Iterable<File> {
return project.configurations.findByName("architecturyTransformerClasspath")
?: project.configurations.getByName("compileClasspath")
?: project.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
}

fun transform(name: String, action: Action<Transform>) {
Expand All @@ -151,7 +155,7 @@ open class ArchitectPluginExtension(val project: Project) {
var plsAddInjectables = false
project.configurations.findByName("architecturyTransformerClasspath")
?: project.configurations.create("architecturyTransformerClasspath") {
it.extendsFrom(project.configurations.getByName("compileClasspath"))
it.extendsFrom(project.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME))
plsAddInjectables = true
}
val architecturyJavaAgents = project.configurations.create("architecturyJavaAgents") {
Expand All @@ -161,10 +165,22 @@ open class ArchitectPluginExtension(val project: Project) {
transformedLoom = true

with(project.dependencies) {
add(
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
"dev.architectury:architectury-transformer:$transformerVersion:runtime"
)
// We are trying to not leak to consumers that we are using architectury-transformer
if (gradle8) {
val customRuntimeClasspath = project.configurations.findByName("architecturyTransformerRuntimeClasspath")
?: project.configurations.create("architecturyTransformerRuntimeClasspath") {
project.configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(it)
}
add(
customRuntimeClasspath.name,
"dev.architectury:architectury-transformer:$transformerVersion:runtime"
)
} else {
add(
JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
"dev.architectury:architectury-transformer:$transformerVersion:runtime"
)
}
add(
"architecturyJavaAgents",
"dev.architectury:architectury-transformer:$transformerVersion:agent"
Expand Down Expand Up @@ -336,7 +352,7 @@ open class ArchitectPluginExtension(val project: Project) {

with(project.dependencies) {
add(
JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
if (gradle8) JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME else JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
"dev.architectury:architectury-injectables:$injectablesVersion"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.architectury.plugin.utils

import org.gradle.api.Project
import org.gradle.api.file.RegularFileProperty
import org.gradle.util.GradleVersion

object GradleSupport {
fun getFileProperty(project: Project): RegularFileProperty {
Expand Down Expand Up @@ -29,4 +30,8 @@ object GradleSupport {
method.isAccessible = true
return method.invoke(`object`) as RegularFileProperty
}

fun isGradle8(project: Project): Boolean {
return GradleVersion.current().baseVersion >= GradleVersion.version("8.0")
}
}

0 comments on commit b0a5920

Please sign in to comment.