Skip to content

Commit

Permalink
Merge pull request #112 from gradlex-org/project-isolation
Browse files Browse the repository at this point in the history
Improve compatibility with Project Isolation
  • Loading branch information
jjohannes authored Jun 4, 2024
2 parents 075ffd7 + fbb7826 commit c3c8b51
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.6.5
* [#104](https://github.com/gradlex-org/java-module-dependencies/issues/104) Fix: ModuleDependencyReport task does not correctly track inputs
* [#105](https://github.com/gradlex-org/java-module-dependencies/issues/105) Improve compatibility with Project Isolation

## Version 1.6.4
* Enhance output of 'moduleDependencies' task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public abstract class JavaModuleDependenciesExtension {
public JavaModuleDependenciesExtension(VersionCatalogsExtension versionCatalogs) {
this.versionCatalogs = versionCatalogs;
this.moduleInfoCache = getObjects().newInstance(ModuleInfoCache.class);
getModulesProperties().set(getProject().getRootProject().getLayout().getProjectDirectory().file("gradle/modules.properties"));
getModulesProperties().set(new File(getProject().getRootDir(), "gradle/modules.properties"));
getVersionCatalogName().convention("libs");
getModuleNameCheck().convention(true);
getAnalyseOnly().convention(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void registerCatalogTask(Project project) {

t.getEntries().addAll(collectCatalogEntriesFromVersions(javaModuleDependencies, moduleVersions));
project.getRootProject().getSubprojects().forEach(sub -> {
File[] srcDirs = sub.getLayout().getProjectDirectory().dir("src").getAsFile().listFiles();
File[] srcDirs = sub.getProjectDir().listFiles();
(srcDirs == null ? Stream.<File>empty() : Arrays.stream(srcDirs)).forEach(srcDirSet -> {
File moduleInfoFile = new File(srcDirSet, "java/module-info.java");
if (!moduleInfoFile.exists()) {
Expand All @@ -144,7 +144,7 @@ private void registerCatalogTask(Project project) {

t.getEntries().addAll();

t.getCatalogFile().set(project.getRootProject().getLayout().getProjectDirectory().file("gradle/libs.versions.toml"));
t.getCatalogFile().set(new File(project.getRootDir(), "gradle/libs.versions.toml"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CustomizationTest extends Specification {
appBuildFile << '''
javaModuleDependencies {
modulesProperties.set(rootProject.layout.projectDirectory.file(".hidden/modules.properties"))
modulesProperties.set(File(rootDir,".hidden/modules.properties"))
}
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GroupMappingTest extends Specification {
'''

when:
def result = runner('assemble').build()
def result = runner(false, 'assemble').build()

then:
result.task(":app:compileJava").outcome == TaskOutcome.SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ class LocalModuleMappingsTest extends Specification {
'''

then:
build()
runner(false, 'build').build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ class RequiresRuntimeTest extends Specification {
tasks.compileTestJava {
classpath += sourceSets.main.get().output
val srcDir = sourceSets.test.get().java.sourceDirectories.first()
options.compilerArgumentProviders.add {
listOf(
"--module-path",
classpath.files.joinToString(":"),
"--patch-module",
"org.gradlex.test.app=" + sourceSets.test.get().java.sourceDirectories.first()
"org.gradlex.test.app=" + srcDir
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class GradleBuild {
mainClass.set("org.gradlex.test.app.Main")
}
tasks.register("printRuntimeJars") {
doLast { println(configurations.runtimeClasspath.get().files.map { it.name }) }
inputs.files(configurations.runtimeClasspath)
doLast { println(inputs.files.map { it.name }) }
}
tasks.register("printCompileJars") {
doLast { println(configurations.compileClasspath.get().files.map { it.name }) }
inputs.files(configurations.compileClasspath)
doLast { println(inputs.files.map { it.name }) }
}
'''
libBuildFile << '''
Expand Down Expand Up @@ -85,12 +87,18 @@ class GradleBuild {
runner('build').buildAndFail()
}

GradleRunner runner(String... args) {
GradleRunner runner(boolean projectIsolation = true, String... args) {
List<String> latestFeaturesArgs = gradleVersionUnderTest || !projectIsolation? [] : [
'--configuration-cache',
'-Dorg.gradle.unsafe.isolated-projects=true',
// 'getGroup' in 'JavaModuleDependenciesExtension.create'
'--configuration-cache-problems=warn', '-Dorg.gradle.configuration-cache.max-problems=3'
]
GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withProjectDir(projectDir)
.withArguments(Arrays.asList(args) + '-s' + '--warning-mode' + 'all')
.withArguments(Arrays.asList(args) + latestFeaturesArgs + '-s' + '--warning-mode=all')
.withDebug(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().contains("-agentlib:jdwp")).with {
gradleVersionUnderTest ? it.withGradleVersion(gradleVersionUnderTest) : it
}
Expand Down

0 comments on commit c3c8b51

Please sign in to comment.