Skip to content

Commit

Permalink
Limit new feature to Gradle 8.8+
Browse files Browse the repository at this point in the history
This is because:
- IsolatedAction is not available earlier
- Using extension accessors in settings file is not available earlier
  • Loading branch information
jjohannes committed Jul 15, 2024
1 parent 5343ab5 commit 04be518
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ testing.suites.named<JvmTestSuite>("test") {
description = "Runs tests against Gradle $gradleVersionUnderTest"
systemProperty("gradleVersionUnderTest", gradleVersionUnderTest)
exclude("**/*SamplesTest.class") // Not yet cross-version ready
exclude("**/initialization/**") // Settings plugin only for latest Gradle version
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@

package org.gradlex.javamodule.dependencies.initialization;

import org.gradle.api.GradleException;
import org.gradle.api.NonNullApi;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.util.GradleVersion;

@NonNullApi
public abstract class JavaModuleDependenciesSettingsPlugin implements Plugin<Settings> {

@Override
public void apply(Settings settings) {
if (GradleVersion.current().compareTo(GradleVersion.version("8.8")) < 0) {
throw new GradleException("This settings plugin requires Gradle 8.8+");
}
registerExtension(settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@

public abstract class JavaModulesExtension {

static final boolean SUPPORT_PROJECT_ISOLATION =
GradleVersion.current().compareTo(GradleVersion.version("8.8")) >= 0;

private final Settings settings;
private final ModuleInfoCache moduleInfoCache;

Expand Down Expand Up @@ -93,11 +90,7 @@ public void versions(String directory) {
String projectName = Paths.get(directory).getFileName().toString();
settings.include(projectName);
settings.project(":" + projectName).setProjectDir(new File(settings.getRootDir(), directory));
if (SUPPORT_PROJECT_ISOLATION) {
settings.getGradle().getLifecycle().beforeProject(new ApplyJavaModuleVersionsPluginAction(projectName));
} else {
settings.getGradle().beforeProject(new ApplyJavaModuleVersionsPluginAction(projectName));
}
settings.getGradle().getLifecycle().beforeProject(new ApplyJavaModuleVersionsPluginAction(projectName));
}

private void includeModule(Module module, File projectDir) {
Expand All @@ -122,11 +115,7 @@ private void includeModule(Module module, File projectDir) {

String group = module.getGroup().getOrNull();
List<String> plugins = module.getPlugins().get();
if (SUPPORT_PROJECT_ISOLATION) {
settings.getGradle().getLifecycle().beforeProject(new ApplyPluginsAction(artifact, group, plugins, mainModuleName, moduleInfoCache));
} else {
settings.getGradle().beforeProject(new ApplyPluginsAction(artifact, group, plugins, mainModuleName, moduleInfoCache));
}
settings.getGradle().getLifecycle().beforeProject(new ApplyPluginsAction(artifact, group, plugins, mainModuleName, moduleInfoCache));
}

@NonNullApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import javax.inject.Inject;

import static org.gradlex.javamodule.dependencies.initialization.JavaModulesExtension.SUPPORT_PROJECT_ISOLATION;

public abstract class RootPluginsExtension {

private final Settings settings;
Expand All @@ -36,11 +34,7 @@ public RootPluginsExtension(Settings settings) {
}

public void id(String id) {
if (SUPPORT_PROJECT_ISOLATION) {
settings.getGradle().getLifecycle().beforeProject(new ApplyPluginAction(id));
} else {
settings.getGradle().beforeProject(new ApplyPluginAction(id));
}
settings.getGradle().getLifecycle().beforeProject(new ApplyPluginAction(id));
}

@NonNullApi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gradlex.javamodule.dependencies.test
package org.gradlex.javamodule.dependencies.test.initialization

import org.gradlex.javamodule.dependencies.test.fixture.GradleBuild
import spock.lang.Specification
Expand Down

0 comments on commit 04be518

Please sign in to comment.