Skip to content

Commit d9209db

Browse files
Merge pull request #301 from rcw3bb/fit-gradle9
Upgrade to version 2.0.0, enhance compatibility with Gradle 9.x
2 parents 50948b1 + d43fec3 commit d9209db

29 files changed

+169
-160
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
steps:
1414
- name: Git checkout
1515
uses: actions/checkout@v4
16-
- name: Set up JDK 11
16+
- name: Set up JDK 17
1717
uses: actions/setup-java@v4
1818
with:
1919
cache: gradle
2020
distribution: microsoft
21-
java-version: 11
21+
java-version: 17
2222
- name: Build with Gradle
2323
run: ./gradlew build --scan

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ jobs:
2323
steps:
2424
- name: Git checkout
2525
uses: actions/checkout@v4
26-
- name: Set up JDK 11
26+
- name: Set up JDK 17
2727
uses: actions/setup-java@v4
2828
with:
2929
cache: gradle
3030
distribution: microsoft
31-
java-version: 11
31+
java-version: 17
3232
- name: Create gradle.properties
3333
run: echo -e "gradle.publish.key=$GRADLE_PUBLISH_KEY\ngradle.publish.secret=$GRADLE_PUBLISH_SECRET" > gradle.properties
3434
- name: Build with Gradle

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ The plugin supports the following test engines:
3232

3333
An example application using this plugin is available [here](https://github.com/java9-modularity/gradle-modules-plugin-example).
3434

35-
Compatability
35+
Compatibility
3636
===
3737

38-
| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
39-
|------------------|-----------------|--------------|----------------|--------------------------------------------------------------------------------------------|
40-
| - -> 1.8.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
41-
| 1.8.12 -> 1.8.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
42-
| 1.8.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
43-
| 1.8.15 -> + | 5.+ -> 8.6.+ | 11+ | 1.6.+ -> 1.9.+ | Fixes compatibility issues with Gradle 8.0.<br>Use JUnit v5.8.0 or above if using Gradle 8 |
38+
| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
39+
| ---------------- | --------------- | ------------ | -------------- | ------------------------------------------------------------ |
40+
| - -> 1.8.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
41+
| 1.8.12 -> 1.8.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
42+
| 1.8.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
43+
| 1.8.15 -> 1.8.x | 5.+ -> 8.6.+ | 11+ | 1.6.+ -> 1.9.+ | Fixes compatibility issues with Gradle 8.0.<br>Use JUnit v5.8.0 or above if using Gradle 8 |
44+
| 2.0.0 | 8.11.+ -> 9.+ | 17+ | 1.8.+ -> 2.x+ | Adds support for Gradle 9.x.<br>Minimum Java version raised to 17 |
4445

4546
Setup
4647
===
@@ -76,7 +77,7 @@ The main build file should look as follows:
7677

7778
```groovy
7879
plugins {
79-
id 'org.javamodularity.moduleplugin' version '1.8.15' apply false
80+
id 'org.javamodularity.moduleplugin' version '2.0.0' apply false
8081
}
8182
8283
subprojects {
@@ -85,8 +86,8 @@ subprojects {
8586
8687
version "1.0-SNAPSHOT"
8788
88-
sourceCompatibility = 11
89-
targetCompatibility = 11
89+
sourceCompatibility = 17
90+
targetCompatibility = 17
9091
9192
repositories {
9293
mavenCentral()
@@ -101,19 +102,21 @@ subprojects {
101102
}
102103
103104
dependencies {
104-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
105-
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.1'
106-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
105+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
106+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
107+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
108+
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.2"
107109
}
108110
}
109111
```
110112
</details>
113+
111114
<details>
112115
<summary>Kotlin DSL</summary>
113116

114117
```kotlin
115118
plugins {
116-
id("org.javamodularity.moduleplugin") version "1.8.15" apply false
119+
id("org.javamodularity.moduleplugin") version "2.0.0" apply false
117120
}
118121

119122
subprojects {
@@ -124,7 +127,7 @@ subprojects {
124127

125128
java {
126129
toolchain {
127-
languageVersion.set(JavaLanguageVersion.of(11))
130+
languageVersion.set(JavaLanguageVersion.of(17))
128131
}
129132
}
130133

@@ -141,9 +144,10 @@ subprojects {
141144
}
142145

143146
dependencies {
144-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
145-
testImplementation("org.junit.jupiter:junit-jupiter-params:5.3.1")
146-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
147+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
148+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
149+
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
150+
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.10.2")
147151
}
148152
}
149153
```
@@ -952,7 +956,7 @@ Please file issues if you run into any problems or have additional requirements!
952956
Requirements
953957
===
954958

955-
This plugin requires JDK 11 or newer to be used when running Gradle.
959+
This latest version of this plugin requires JDK 17 or newer to be used when running Gradle. Older versions support JDK 11.
956960

957961
The minimum Gradle version supported by this plugin is 5.1.
958962
However, we strongly recommend to use at least Gradle 6.0, because there are a few special cases that cannot be handled correctly when using older versions.

build.gradle

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ plugins {
33
id 'java-gradle-plugin'
44
id 'maven-publish' // used for publishing to local maven repository
55
id 'com.gradle.plugin-publish' version '1.2.1'
6-
id 'com.github.johnrengelman.shadow' version '7.1.2'
6+
id 'com.gradleup.shadow' version '9.2.2'
77
id 'com.github.ben-manes.versions' version '0.51.0'
88
}
99

10-
buildScan {
11-
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
12-
termsOfServiceAgree = 'yes'
10+
develocity {
11+
buildScan {
12+
termsOfUseUrl = 'https://gradle.com/help/legal-terms-of-use'
13+
termsOfUseAgree = 'yes'
14+
}
1315
}
1416

1517
group 'org.javamodularity'
16-
version '1.8.16-SNAPSHOT'
18+
version '2.0.0'
1719

18-
sourceCompatibility = 11
19-
targetCompatibility = 11
20+
java {
21+
sourceCompatibility = JavaVersion.VERSION_11
22+
targetCompatibility = JavaVersion.VERSION_11
23+
}
2024

2125
repositories {
2226
mavenCentral()
@@ -39,8 +43,8 @@ dependencies {
3943
testImplementation 'com.google.guava:guava-io:r03'
4044
testImplementation "org.junit.jupiter:junit-jupiter-api:$jUnitVersion"
4145
testImplementation "org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
46+
testImplementation "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
4247
testImplementation 'org.junit-pioneer:junit-pioneer:2.3.0'
43-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
4448
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // required when testing in Eclipse
4549
}
4650

@@ -96,21 +100,18 @@ dependencies {
96100

97101
gradlePlugin {
98102
plugins {
103+
website = 'https://github.com/java9-modularity/gradle-modules-plugin'
104+
vcsUrl = 'https://github.com/java9-modularity/gradle-modules-plugin'
99105
modulesPlugin {
100106
id = 'org.javamodularity.moduleplugin'
101107
displayName = 'Java Modularity Gradle Plugin'
102108
description = 'Plugin that makes it easy to work with the Java Platform Module System'
103109
implementationClass = 'org.javamodularity.moduleplugin.ModuleSystemPlugin'
110+
tags = ['java', 'modules', 'jpms', 'modularity']
104111
}
105112
}
106113
}
107114

108-
pluginBundle {
109-
website = 'https://github.com/java9-modularity/gradle-modules-plugin'
110-
vcsUrl = 'https://github.com/java9-modularity/gradle-modules-plugin'
111-
tags = ['java', 'modules', 'jpms', 'modularity']
112-
}
113-
114115
publishing { // used for publishing to local maven repository
115116
publications {
116117
pluginMaven(MavenPublication) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "com.gradle.enterprise" version "3.17.4"
2+
id "com.gradle.develocity" version "4.2.1"
33
}
44

55
rootProject.name = 'moduleplugin'

src/main/java/org/javamodularity/moduleplugin/TestEngine.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,17 @@ public static Collection<TestEngine> selectMultiple(Project project, Set<File> f
104104

105105
}
106106

107+
private static Stream<GroupArtifact> getDirectDependencies(Configuration origCfg) {
108+
LOGGER.debug("Configuration {} cannot be resolved, using direct dependencies only", origCfg.getName());
109+
return origCfg.getDependencies().stream()
110+
.map(dep -> new GroupArtifact(dep.getGroup(), dep.getName()));
111+
}
112+
107113
private static Stream<GroupArtifact> getModuleIdentifiers(Configuration origCfg, Set<File> files) {
114+
if (!origCfg.isCanBeResolved()) {
115+
return getDirectDependencies(origCfg);
116+
}
117+
108118
Configuration cfg = origCfg.copyRecursive();
109119
cfg.setCanBeResolved(true);
110120
try {
@@ -116,9 +126,7 @@ private static Stream<GroupArtifact> getModuleIdentifiers(Configuration origCfg,
116126
.map(dep -> GroupArtifact.fromModuleIdentifier(dep.getModule().getId().getModule()));
117127
} catch (ResolveException e) {
118128
LOGGER.debug("Cannot resolve transitive dependencies of configuration " + cfg.getName(), e);
119-
LOGGER.info("Using direct dependencies of configuration {}.", origCfg.getName());
120-
return origCfg.getDependencies().stream()
121-
.map(dep -> new GroupArtifact(dep.getGroup(), dep.getName()));
129+
return getDirectDependencies(origCfg);
122130
}
123131
}
124132

src/main/java/org/javamodularity/moduleplugin/internal/CompileModuleInfoHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import org.gradle.api.Project;
44
import org.gradle.api.Task;
5+
import org.gradle.api.artifacts.Dependency;
56
import org.gradle.api.artifacts.ProjectDependency;
67
import org.gradle.api.logging.Logger;
78
import org.gradle.api.logging.Logging;
9+
import org.gradle.api.tasks.TaskContainer;
810
import org.gradle.api.tasks.compile.JavaCompile;
11+
import org.gradle.util.GradleVersion;
912
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions;
1013

1114
import java.util.Objects;
15+
import java.util.function.Function;
1216
import java.util.stream.Stream;
1317

1418
public final class CompileModuleInfoHelper {
@@ -32,10 +36,14 @@ public static void dependOnOtherCompileModuleInfoJavaTasks(JavaCompile javaCompi
3236
* @return a {@link Stream} of {@code compileModuleInfoJava} tasks from dependent projects
3337
*/
3438
private static Stream<Task> dependentCompileModuleInfoJavaTaskStream(Project project) {
39+
final Function<Dependency, TaskContainer> mapToTaskContainer = dependency ->
40+
project.project(((ProjectDependency) dependency)
41+
.getPath() /* ProjectDependency.getPath() introduced in Gradle 8.11 */).getTasks();
42+
3543
return project.getConfigurations().stream()
3644
.flatMap(configuration -> configuration.getDependencies().stream())
3745
.filter(dependency -> dependency instanceof ProjectDependency)
38-
.map(dependency -> ((ProjectDependency) dependency).getDependencyProject().getTasks())
46+
.map(mapToTaskContainer)
3947
.map(tasks -> tasks.findByName(CompileModuleOptions.COMPILE_MODULE_INFO_TASK_NAME))
4048
.filter(Objects::nonNull)
4149
.filter(task -> task.getProject() != project);

src/main/java/org/javamodularity/moduleplugin/tasks/AbstractExecutionMutator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractExecutionMutator {
2424
protected final String getMainClassName() {
2525
if(GradleVersion.current().compareTo(GradleVersion.version("6.4")) < 0) {
2626
String mainClassName = Objects.requireNonNull(
27-
execTask.getMain(),
27+
execTask.getMainClass().getOrNull(),
2828
"Main class name not found. Try setting 'application.mainClassName' in your Gradle build file."
2929
);
3030
if (!mainClassName.contains("/")) {

src/main/java/org/javamodularity/moduleplugin/tasks/CompileModuleInfoTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void execute(Task task) {
7171
// https://docs.gradle.org/6.1/javadoc/org/gradle/api/file/SourceDirectorySet.html#getClassesDirectory--
7272
classesDir = helper().mainSourceSet().getJava().getClassesDirectory().get().getAsFile();
7373
} else {
74-
classesDir = helper().mainSourceSet().getJava().getOutputDir();
74+
classesDir = helper().mainSourceSet().getJava().getDestinationDirectory().get().getAsFile();
7575
}
7676

7777
File mainModuleInfoFile = new File(classesDir, "module-info.class");

0 commit comments

Comments
 (0)