Skip to content

Commit 27e4bfd

Browse files
committed
Make assemble configuration cache compatible
1 parent 13c1974 commit 27e4bfd

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

buildSrc/src/main/kotlin/java-library-conventions.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ val compileModule by tasks.registering(JavaCompile::class) {
157157
"-Werror", // Terminates compilation when warnings occur.
158158
"--module-version", "${project.version}",
159159
))
160-
options.compilerArgumentProviders.add(ModulePathArgumentProvider(project, modularProjects))
161-
options.compilerArgumentProviders.addAll(modularProjects.map { PatchModuleArgumentProvider(project, it) })
160+
options.compilerArgumentProviders.add(objects.newInstance(ModulePathArgumentProvider::class, project, modularProjects))
161+
options.compilerArgumentProviders.addAll(modularProjects.map { objects.newInstance(PatchModuleArgumentProvider::class, project, it) })
162162
modularity.inferModulePath.set(false)
163163
}
164164

buildSrc/src/main/kotlin/org/junit/gradle/java/ModulePathArgumentProvider.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@ package org.junit.gradle.java
33
import org.gradle.api.Named
44
import org.gradle.api.Project
55
import org.gradle.api.artifacts.Configuration
6+
import org.gradle.api.file.ConfigurableFileCollection
67
import org.gradle.api.file.FileCollection
8+
import org.gradle.api.provider.Property
79
import org.gradle.api.provider.Provider
810
import org.gradle.api.tasks.*
911
import org.gradle.kotlin.dsl.get
1012
import org.gradle.process.CommandLineArgumentProvider
13+
import javax.inject.Inject
1114

12-
class ModulePathArgumentProvider(project: Project, modularProjects: List<Project>) : CommandLineArgumentProvider,
13-
Named {
15+
abstract class ModulePathArgumentProvider @Inject constructor(project: Project, modularProjects: List<Project>) :
16+
CommandLineArgumentProvider, Named {
1417

1518
@get:CompileClasspath
16-
val modulePath: Provider<Configuration> = project.configurations.named("compileClasspath")
19+
abstract val modulePath: ConfigurableFileCollection
1720

1821
@get:InputFiles
1922
@get:PathSensitive(PathSensitivity.RELATIVE)
20-
val moduleSourceDirs: FileCollection = project.files(modularProjects.map { "${it.projectDir}/src/module" })
23+
abstract val moduleSourceDirs: ConfigurableFileCollection
24+
25+
init {
26+
modulePath.from(project.configurations.named("compileClasspath"))
27+
modularProjects.forEach {
28+
moduleSourceDirs.from(project.files("${it.projectDir}/src/module"))
29+
}
30+
}
2131

2232
override fun asArguments() = listOf(
2333
"--module-path",
24-
modulePath.get().asPath,
34+
modulePath.asPath,
2535
"--module-source-path",
2636
moduleSourceDirs.asPath
2737
)

buildSrc/src/main/kotlin/org/junit/gradle/java/PatchModuleArgumentProvider.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,45 @@ package org.junit.gradle.java
33
import javaModuleName
44
import org.gradle.api.Named
55
import org.gradle.api.Project
6+
import org.gradle.api.file.ConfigurableFileCollection
67
import org.gradle.api.file.FileCollection
8+
import org.gradle.api.provider.Property
79
import org.gradle.api.provider.Provider
810
import org.gradle.api.tasks.*
911
import org.gradle.kotlin.dsl.get
1012
import org.gradle.kotlin.dsl.the
1113
import org.gradle.process.CommandLineArgumentProvider
14+
import javax.inject.Inject
1215

13-
class PatchModuleArgumentProvider(compiledProject: Project, patchModuleProject: Project) : CommandLineArgumentProvider,
14-
Named {
16+
abstract class PatchModuleArgumentProvider @Inject constructor(compiledProject: Project, patchModuleProject: Project) :
17+
CommandLineArgumentProvider, Named {
1518

16-
@get:Input
17-
val module: String = patchModuleProject.javaModuleName
19+
@get:Input
20+
abstract val module: Property<String>
1821

19-
@get:InputFiles
20-
@get:PathSensitive(PathSensitivity.RELATIVE)
21-
val patch: Provider<FileCollection> = compiledProject.provider {
22-
if (patchModuleProject == compiledProject)
23-
compiledProject.files(compiledProject.the<SourceSetContainer>().matching { it.name.startsWith("main") }.map { it.output })
24-
else
25-
patchModuleProject.files(patchModuleProject.the<SourceSetContainer>()["main"].java.srcDirs)
26-
}
22+
@get:InputFiles
23+
@get:PathSensitive(PathSensitivity.RELATIVE)
24+
abstract val patch: ConfigurableFileCollection
2725

28-
override fun asArguments(): List<String> {
29-
val path = patch.get().filter { it.exists() }.asPath
30-
if (path.isEmpty()) {
31-
return emptyList()
32-
}
33-
return listOf("--patch-module", "$module=$path")
34-
}
26+
init {
27+
module.convention(patchModuleProject.javaModuleName)
28+
patch.from(compiledProject.provider {
29+
if (patchModuleProject == compiledProject)
30+
compiledProject.files(compiledProject.the<SourceSetContainer>().matching { it.name.startsWith("main") }
31+
.map { it.output })
32+
else
33+
patchModuleProject.files(patchModuleProject.the<SourceSetContainer>()["main"].java.srcDirs)
34+
})
35+
}
3536

36-
@Internal
37-
override fun getName() = "patch-module($module)"
37+
override fun asArguments(): List<String> {
38+
val path = patch.filter { it.exists() }.asPath
39+
if (path.isEmpty()) {
40+
return emptyList()
41+
}
42+
return listOf("--patch-module", "${module.get()}=$path")
43+
}
44+
45+
@Internal
46+
override fun getName() = "patch-module(${module.get()})"
3847
}

0 commit comments

Comments
 (0)