Skip to content

Commit f8b9a65

Browse files
committed
Remove merged Jars from classpath even if they are (automatic) modules
Fixes #50
1 parent ec461a0 commit f8b9a65

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Extra Java Module Info Gradle Plugin - Changelog
22

3+
## Version 1.4.1
4+
* [Fixed] [#50](https://github.com/gradlex-org/extra-java-module-info/issues/50) Remove merged Jars from classpath even if they are (automatic) modules
5+
36
## Version 1.4
47
* [New] Minimal Gradle version is now 6.8 for integration with recently added features like the Dependency Version Catalog
58
* [New] [#46](https://github.com/gradlex-org/extra-java-module-info/issues/46) - Validation coordinates and module names

src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public void transform(TransformOutputs outputs) {
104104

105105
ModuleSpec moduleSpec = findModuleSpec(originalJar);
106106

107+
if (willBeMerged(originalJar, moduleSpecs.values())) { // No output if this Jar will be merged
108+
return;
109+
}
110+
107111
if (moduleSpec instanceof ModuleInfo) {
108112
addModuleDescriptor(originalJar, getModuleJar(outputs, originalJar), (ModuleInfo) moduleSpec);
109113
} else if (moduleSpec instanceof AutomaticModuleName) {
@@ -112,7 +116,7 @@ public void transform(TransformOutputs outputs) {
112116
outputs.file(originalJar);
113117
} else if (isAutoModule(originalJar)) {
114118
outputs.file(originalJar);
115-
} else if (!willBeMerged(originalJar, moduleSpecs.values())) { // No output if this Jar will be merged
119+
} else {
116120
if (getParameters().getFailOnMissingModuleInfo().get()) {
117121
throw new RuntimeException("Not a module and no mapping defined: " + originalJar.getName());
118122
} else {

src/test/groovy/org/gradlex/javamodule/moduleinfo/test/EdgeCasesFunctionalTest.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,45 @@ class EdgeCasesFunctionalTest extends Specification {
9898
!result.output.contains('qpid-broker-plugins-management-http-9.0.0.jar')
9999
}
100100

101+
def "can merge jars that are already modules"() {
102+
given:
103+
file("src/main/java/org/gradle/sample/app/Main.java") << """
104+
package org.gradle.sample.app;
105+
106+
public class Main {
107+
public static void main(String[] args) throws Exception {
108+
}
109+
}
110+
"""
111+
file("src/main/java/module-info.java") << """
112+
module org.gradle.sample.app {
113+
requires java.annotation;
114+
}
115+
"""
116+
buildFile << """
117+
dependencies {
118+
implementation("com.google.code.findbugs:jsr305:3.0.2")
119+
implementation("javax.annotation:javax.annotation-api:1.3.2")
120+
}
121+
122+
extraJavaModuleInfo {
123+
module("com.google.code.findbugs:jsr305", "java.annotation") {
124+
mergeJar("javax.annotation:javax.annotation-api")
125+
exports("javax.annotation")
126+
exports("javax.annotation.concurrent")
127+
exports("javax.annotation.meta")
128+
}
129+
}
130+
131+
tasks.named("run") {
132+
doLast { println(configurations.runtimeClasspath.get().files.map { it.name }) }
133+
}
134+
"""
135+
136+
when:
137+
def result = run()
138+
139+
then:
140+
result.output.contains('[jsr305-3.0.2-module.jar]')
141+
}
101142
}

0 commit comments

Comments
 (0)