Skip to content

Commit 6241ec3

Browse files
authored
Merge pull request #48800 from reaver585/sync-file-dep-jar-naming-for-gradle
Sync naming convention for file dependency JARs
2 parents cd7ad91 + 32c1d55 commit 6241ec3

File tree

8 files changed

+116
-8
lines changed

8 files changed

+116
-8
lines changed

core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,7 @@ private void copyDependency(Set<ArtifactKey> parentFirstArtifacts, OutputTargetB
920920
return;
921921
}
922922
for (Path resolvedDep : appDep.getResolvedPaths()) {
923-
final boolean isDirectory = Files.isDirectory(resolvedDep);
924-
// we don't use getFileName() for directories, since directories would often be "classes" ending up merging content from multiple dependencies in the same package
925-
final String fileName = isDirectory ? getFileNameForDirectory(appDep)
926-
: appDep.getGroupId() + "." + resolvedDep.getFileName();
923+
final String fileName = getJarFileName(appDep, resolvedDep);
927924
final Path targetPath;
928925

929926
if (allowParentFirst && parentFirstArtifacts.contains(appDep.getKey())) {
@@ -935,7 +932,7 @@ private void copyDependency(Set<ArtifactKey> parentFirstArtifacts, OutputTargetB
935932
}
936933
runtimeArtifacts.computeIfAbsent(appDep.getKey(), (s) -> new ArrayList<>(1)).add(targetPath);
937934

938-
if (isDirectory) {
935+
if (Files.isDirectory(resolvedDep)) {
939936
// This case can happen when we are building a jar from inside the Quarkus repository
940937
// and Quarkus Bootstrap's localProjectDiscovery has been set to true. In such a case
941938
// the non-jar dependencies are the Quarkus dependencies picked up on the file system
@@ -976,12 +973,20 @@ private void copyDependency(Set<ArtifactKey> parentFirstArtifacts, OutputTargetB
976973
}
977974

978975
/**
979-
* Returns a JAR file name to be used for a content of a dependency that is in a directory.
976+
* Returns a JAR file name to be used for a content of a dependency, depending on whether the resolved path
977+
* is a directory or not.
978+
* We don't use getFileName() for directories, since directories would often be "classes" ending up merging
979+
* content from multiple dependencies in the same package
980980
*
981981
* @param dep dependency
982+
* @param resolvedPath path of the resolved dependency
982983
* @return JAR file name
983984
*/
984-
private static String getFileNameForDirectory(ResolvedDependency dep) {
985+
public static String getJarFileName(ResolvedDependency dep, Path resolvedPath) {
986+
boolean isDirectory = Files.isDirectory(resolvedPath);
987+
if (!isDirectory) {
988+
return dep.getGroupId() + "." + resolvedPath.getFileName();
989+
}
985990
final StringBuilder sb = new StringBuilder();
986991
sb.append(dep.getGroupId()).append(".").append(dep.getArtifactId()).append("-");
987992
if (!dep.getClassifier().isEmpty()) {

devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.quarkus.bootstrap.model.ApplicationModel;
2121
import io.quarkus.deployment.pkg.PackageConfig;
22+
import io.quarkus.deployment.pkg.steps.JarResultBuildStep;
2223
import io.quarkus.fs.util.ZipUtils;
2324
import io.quarkus.gradle.QuarkusPlugin;
2425
import io.quarkus.maven.dependency.ArtifactKey;
@@ -184,7 +185,7 @@ private void jarDependencies(Path libBoot, Path libMain) {
184185
ResolvedDependency dep = depAndTarget.getValue();
185186
Path targetDir = depAndTarget.getKey();
186187
dep.getResolvedPaths().forEach(p -> {
187-
String file = dep.getGroupId() + '.' + p.getFileName();
188+
String file = JarResultBuildStep.getJarFileName(dep, p);
188189
Path target = targetDir.resolve(file);
189190
if (!Files.exists(target)) {
190191
getLogger().debug("Dependency {} : copying {} to {}",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
plugins {
2+
id 'java'
3+
id 'io.quarkus'
4+
}
5+
6+
repositories {
7+
mavenLocal {
8+
content {
9+
includeGroupByRegex 'io.quarkus.*'
10+
includeGroup 'org.hibernate.orm'
11+
}
12+
}
13+
mavenCentral()
14+
gradlePluginPortal()
15+
}
16+
17+
sourceSets {
18+
additional {
19+
java {
20+
srcDir "src/gen/java"
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
27+
implementation sourceSets.additional.output
28+
implementation 'io.quarkus:quarkus-arc'
29+
implementation 'io.quarkus:quarkus-rest'
30+
}
31+
32+
group 'org.acme'
33+
version '1.0.0-SNAPSHOT'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quarkusPlatformArtifactId=quarkus-bom
2+
quarkusPlatformGroupId=io.quarkus
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pluginManagement {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
plugins {
13+
id 'io.quarkus' version "${quarkusPluginVersion}"
14+
}
15+
}
16+
rootProject.name = 'additional-source-set-as-dependency'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.reproducer;
2+
3+
public interface GreetApi {
4+
5+
public String hello();
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.acme;
2+
3+
import io.reproducer.GreetApi;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
import jakarta.ws.rs.Produces;
7+
import jakarta.ws.rs.core.MediaType;
8+
9+
@Path("/hello")
10+
public class GreetingResource implements GreetApi {
11+
12+
@GET
13+
@Produces(MediaType.TEXT_PLAIN)
14+
public String hello() {
15+
return "Hello from Quarkus REST...";
16+
}
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.quarkus.gradle.run;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.quarkus.gradle.devmode.QuarkusDevGradleTestBase;
6+
7+
// Reproduces https://github.com/quarkusio/quarkus/issues/48768.
8+
// Despite extending QuarkusDevGradleTestBase, this test does not use the dev mode,
9+
// but rather runs the application in a production mode using `quarkusRun` task.
10+
// At this point it's the only test that does so, but if more such tests are added,
11+
// perhaps it would make sense to create a separate base class for them.
12+
public class AdditionalSourceSetAsDependencyTest extends QuarkusDevGradleTestBase {
13+
14+
@Override
15+
protected String projectDirectoryName() {
16+
return "additional-source-set-as-dependency";
17+
}
18+
19+
@Override
20+
protected String[] buildArguments() {
21+
return new String[] { "clean", "quarkusRun" };
22+
}
23+
24+
@Override
25+
protected void testDevMode() throws Exception {
26+
assertThat(getHttpResponse("/hello")).contains("Hello from Quarkus REST...");
27+
}
28+
}

0 commit comments

Comments
 (0)