Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
cache: gradle
distribution: microsoft
java-version: 11
java-version: 17
- name: Build with Gradle
run: ./gradlew build --scan
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
cache: gradle
distribution: microsoft
java-version: 11
java-version: 17
- name: Create gradle.properties
run: echo -e "gradle.publish.key=$GRADLE_PUBLISH_KEY\ngradle.publish.secret=$GRADLE_PUBLISH_SECRET" > gradle.properties
- name: Build with Gradle
Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ The plugin supports the following test engines:

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

Compatability
Compatibility
===

| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
|------------------|-----------------|--------------|----------------|--------------------------------------------------------------------------------------------|
| - -> 1.8.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
| 1.8.12 -> 1.8.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
| 1.8.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
| 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 |
| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
| ---------------- | --------------- | ------------ | -------------- | ------------------------------------------------------------ |
| - -> 1.8.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
| 1.8.12 -> 1.8.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
| 1.8.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
| 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 |
| 2.0.0 | 8.11.+ -> 9.+ | 17+ | 1.8.+ -> 2.x+ | Adds support for Gradle 9.x.<br>Minimum Java version raised to 17 |

Setup
===
Expand Down Expand Up @@ -76,7 +77,7 @@ The main build file should look as follows:

```groovy
plugins {
id 'org.javamodularity.moduleplugin' version '1.8.15' apply false
id 'org.javamodularity.moduleplugin' version '2.0.0' apply false
}

subprojects {
Expand All @@ -85,8 +86,8 @@ subprojects {

version "1.0-SNAPSHOT"

sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = 17
targetCompatibility = 17

repositories {
mavenCentral()
Expand All @@ -101,19 +102,21 @@ subprojects {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.2"
}
}
```
</details>

<details>
<summary>Kotlin DSL</summary>

```kotlin
plugins {
id("org.javamodularity.moduleplugin") version "1.8.15" apply false
id("org.javamodularity.moduleplugin") version "2.0.0" apply false
}

subprojects {
Expand All @@ -124,7 +127,7 @@ subprojects {

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}
}

Expand All @@ -141,9 +144,10 @@ subprojects {
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.3.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.10.2")
}
}
```
Expand Down Expand Up @@ -952,7 +956,7 @@ Please file issues if you run into any problems or have additional requirements!
Requirements
===

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

The minimum Gradle version supported by this plugin is 5.1.
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.
Expand Down
29 changes: 15 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ plugins {
id 'java-gradle-plugin'
id 'maven-publish' // used for publishing to local maven repository
id 'com.gradle.plugin-publish' version '1.2.1'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.gradleup.shadow' version '9.2.2'
id 'com.github.ben-manes.versions' version '0.51.0'
}

buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
develocity {
buildScan {
termsOfUseUrl = 'https://gradle.com/help/legal-terms-of-use'
termsOfUseAgree = 'yes'
}
}

group 'org.javamodularity'
version '1.8.16-SNAPSHOT'
version '2.0.0'

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

repositories {
mavenCentral()
Expand All @@ -39,8 +43,8 @@ dependencies {
testImplementation 'com.google.guava:guava-io:r03'
testImplementation "org.junit.jupiter:junit-jupiter-api:$jUnitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
testImplementation 'org.junit-pioneer:junit-pioneer:2.3.0'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // required when testing in Eclipse
}

Expand Down Expand Up @@ -96,21 +100,18 @@ dependencies {

gradlePlugin {
plugins {
website = 'https://github.com/java9-modularity/gradle-modules-plugin'
vcsUrl = 'https://github.com/java9-modularity/gradle-modules-plugin'
modulesPlugin {
id = 'org.javamodularity.moduleplugin'
displayName = 'Java Modularity Gradle Plugin'
description = 'Plugin that makes it easy to work with the Java Platform Module System'
implementationClass = 'org.javamodularity.moduleplugin.ModuleSystemPlugin'
tags = ['java', 'modules', 'jpms', 'modularity']
}
}
}

pluginBundle {
website = 'https://github.com/java9-modularity/gradle-modules-plugin'
vcsUrl = 'https://github.com/java9-modularity/gradle-modules-plugin'
tags = ['java', 'modules', 'jpms', 'modularity']
}

publishing { // used for publishing to local maven repository
publications {
pluginMaven(MavenPublication) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.gradle.enterprise" version "3.17.4"
id "com.gradle.develocity" version "4.2.1"
}

rootProject.name = 'moduleplugin'
14 changes: 11 additions & 3 deletions src/main/java/org/javamodularity/moduleplugin/TestEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ public static Collection<TestEngine> selectMultiple(Project project, Set<File> f

}

private static Stream<GroupArtifact> getDirectDependencies(Configuration origCfg) {
LOGGER.debug("Configuration {} cannot be resolved, using direct dependencies only", origCfg.getName());
return origCfg.getDependencies().stream()
.map(dep -> new GroupArtifact(dep.getGroup(), dep.getName()));
}

private static Stream<GroupArtifact> getModuleIdentifiers(Configuration origCfg, Set<File> files) {
if (!origCfg.isCanBeResolved()) {
return getDirectDependencies(origCfg);
}

Configuration cfg = origCfg.copyRecursive();
cfg.setCanBeResolved(true);
try {
Expand All @@ -116,9 +126,7 @@ private static Stream<GroupArtifact> getModuleIdentifiers(Configuration origCfg,
.map(dep -> GroupArtifact.fromModuleIdentifier(dep.getModule().getId().getModule()));
} catch (ResolveException e) {
LOGGER.debug("Cannot resolve transitive dependencies of configuration " + cfg.getName(), e);
LOGGER.info("Using direct dependencies of configuration {}.", origCfg.getName());
return origCfg.getDependencies().stream()
.map(dep -> new GroupArtifact(dep.getGroup(), dep.getName()));
return getDirectDependencies(origCfg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.util.GradleVersion;
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions;

import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;

public final class CompileModuleInfoHelper {
Expand All @@ -32,10 +36,14 @@ public static void dependOnOtherCompileModuleInfoJavaTasks(JavaCompile javaCompi
* @return a {@link Stream} of {@code compileModuleInfoJava} tasks from dependent projects
*/
private static Stream<Task> dependentCompileModuleInfoJavaTaskStream(Project project) {
final Function<Dependency, TaskContainer> mapToTaskContainer = dependency ->
project.project(((ProjectDependency) dependency)
.getPath() /* ProjectDependency.getPath() introduced in Gradle 8.11 */).getTasks();

return project.getConfigurations().stream()
.flatMap(configuration -> configuration.getDependencies().stream())
.filter(dependency -> dependency instanceof ProjectDependency)
.map(dependency -> ((ProjectDependency) dependency).getDependencyProject().getTasks())
.map(mapToTaskContainer)
.map(tasks -> tasks.findByName(CompileModuleOptions.COMPILE_MODULE_INFO_TASK_NAME))
.filter(Objects::nonNull)
.filter(task -> task.getProject() != project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractExecutionMutator {
protected final String getMainClassName() {
if(GradleVersion.current().compareTo(GradleVersion.version("6.4")) < 0) {
String mainClassName = Objects.requireNonNull(
execTask.getMain(),
execTask.getMainClass().getOrNull(),
"Main class name not found. Try setting 'application.mainClassName' in your Gradle build file."
);
if (!mainClassName.contains("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void execute(Task task) {
// https://docs.gradle.org/6.1/javadoc/org/gradle/api/file/SourceDirectorySet.html#getClassesDirectory--
classesDir = helper().mainSourceSet().getJava().getClassesDirectory().get().getAsFile();
} else {
classesDir = helper().mainSourceSet().getJava().getOutputDir();
classesDir = helper().mainSourceSet().getJava().getDestinationDirectory().get().getAsFile();
}

File mainModuleInfoFile = new File(classesDir, "module-info.class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.plugins.ApplicationPluginConvention;
import org.gradle.api.plugins.JavaApplication;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.application.CreateStartScripts;

Expand All @@ -22,22 +24,22 @@ public ModularCreateStartScripts() {
setClasspath(getProject().files());
}

@Input
@Nullable
@Override
public String getMainClassName() {
String main = changedMain;
if(main == null) {
main = super.getMainClassName();
main = super.getMainClass().getOrNull();
}
if(main == null) {
main = UNDEFINED_MAIN_CLASS_NAME;
}
return main;
}

@Override
public void setMainClassName(@Nullable String mainClassName) {
changedMain = mainClassName;
getMainClass().set(mainClassName);
}

public ModularJavaExec getRunTask() {
Expand All @@ -59,10 +61,10 @@ private static void configureAfterEvaluate(Project project) {
}

private static void configure(ModularCreateStartScripts startScriptsTask, Project project) {
var appConvention = project.getConvention().findPlugin(ApplicationPluginConvention.class);
if (appConvention != null) {
var distDir = project.file(project.getBuildDir() + "/install/" + appConvention.getApplicationName());
startScriptsTask.setOutputDir(new File(distDir, appConvention.getExecutableDir()));
final var appExtension = project.getExtensions().findByType(JavaApplication.class);
if (appExtension != null) {
var distDir = project.file(project.getLayout().getBuildDirectory().get().getAsFile() + "/install/" + appExtension.getApplicationName());
startScriptsTask.setOutputDir(new File(distDir, appExtension.getExecutableDir()));
}

ModularJavaExec runTask = startScriptsTask.getRunTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,12 @@ public void setJvmArgs(Iterable<?> arguments) {
}

@Input
@Override
public String getMain() {
if(GradleVersion.current().compareTo(GradleVersion.version("6.4")) >= 0) {
return stripModule(getMainClass().getOrNull());
} else {
return super.getMain();
}
return stripModule(getMainClass().getOrNull());
}

@Override
public JavaExec setMain(String mainClassName) {
if(GradleVersion.current().compareTo(GradleVersion.version("6.4")) >= 0) {
getMainClass().set(stripModule(mainClassName));
} else {
super.setMain(mainClassName);
}
getMainClass().set(stripModule(mainClassName));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ private void configureStartScriptsDoFirst(CreateStartScripts startScriptsTask) {
startScriptsTask.setDefaultJvmOpts(jvmArgs);
startScriptsTask.setClasspath(project.files());

if(GradleVersion.current().compareTo(GradleVersion.version("6.4")) < 0) {
if (ModularCreateStartScripts.UNDEFINED_MAIN_CLASS_NAME.equals(startScriptsTask.getMainClassName())) {
startScriptsTask.setMainClassName(execTask.getMain());
}
final var mainClass = startScriptsTask.getMainClass();
if (ModularCreateStartScripts.UNDEFINED_MAIN_CLASS_NAME.equals(mainClass.getOrNull())) {
mainClass.set(execTask.getMainClass());
}
}

Expand Down
Loading