Skip to content

Commit

Permalink
Let 'javaModulesMergeJars' extend 'internal' if available (#143)
Browse files Browse the repository at this point in the history
Resolves #138
  • Loading branch information
jjohannes authored Sep 21, 2024
1 parent f110980 commit 6b72840
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ private void configureTransform(Project project, ExtraJavaModuleInfoPluginExtens
}
});

// If 'internal' is added by 'org.gradlex.jvm-dependency-conflict-resolution', extend from it to get access to versions
project.getConfigurations().all(otherConfiguration -> {
if ("internal".equals(otherConfiguration.getName())) {
javaModulesMergeJars.extendsFrom(otherConfiguration);
}
});

Attribute<String> artifactType = Attribute.of("artifactType", String.class);
Attribute<Boolean> javaModule = Attribute.of("javaModule", Boolean.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,69 @@ class CombinationWithOtherPluginsFunctionalTest extends Specification {
settingsFile << 'rootProject.name = "test-project"'
}

def "mergeJar uses versions configured through jvm-dependency-conflict-resolution plugin"() {
given:
file("src/main/java/org/gradle/sample/app/Main.java") << """
package org.gradle.sample.app;
public class Main {
public static void main(String[] args) {
Class<?> loggerFromApi = org.slf4j.Logger.class;
Class<?> ndcFromExt = org.slf4j.NDC.class;
}
}
"""
file("src/main/java/module-info.java") << """
module org.gradle.sample.app {
requires org.slf4j;
}
"""
settingsFile << """
include("versions")
"""
file('versions/build.gradle.kts') << """
plugins { id("java-platform") }
dependencies.constraints {
api("org.slf4j:slf4j-api:1.7.32")
api("org.slf4j:slf4j-ext:1.7.32")
}
"""
buildFile << """
plugins {
id("application")
id("org.gradlex.extra-java-module-info")
id("org.gradlex.jvm-dependency-conflict-resolution") version "2.1.2"
}
application.mainClass.set("org.gradle.sample.app.Main")
dependencies {
implementation("org.slf4j:slf4j-api")
}
jvmDependencyConflicts {
consistentResolution {
providesVersions(":")
platform(":versions")
}
}
extraJavaModuleInfo {
automaticModule("org.slf4j:slf4j-api", "org.slf4j") {
mergeJar("org.slf4j:slf4j-ext")
}
}
tasks.named("run") {
inputs.files(configurations.runtimeClasspath)
doLast { println(inputs.files.map { it.name }) }
}
"""

when:
def result = run()

then:
result.task(":run").outcome == TaskOutcome.SUCCESS
result.output.contains('slf4j-api-1.7.32-module.jar')
!result.output.contains('slf4j-api-1.7.32.jar')
!result.output.contains('slf4j-ext-1.7.32.jar')
}

@IgnoreIf({ !GradleBuild.gradleVersionUnderTest?.startsWith('7.') })
def "works in combination with shadow plugin"() {
def shadowJar = file("app/build/libs/app-all.jar")
Expand Down

0 comments on commit 6b72840

Please sign in to comment.