Skip to content

Commit

Permalink
Merge pull request #20435 from glefloch/fix/20419
Browse files Browse the repository at this point in the history
Handle dependency constraint in gradle conditional dependency resolution
  • Loading branch information
glefloch authored Sep 29, 2021
2 parents 8e64eb9 + a9edc5f commit 04801d9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static Configuration duplicateConfiguration(Project project, Configuratio
configurationCopy.getDependencies().addAll(boms);

for (Configuration toDuplicate : toDuplicates) {
configurationCopy.getDependencyConstraints().addAll(toDuplicate.getAllDependencyConstraints());
for (Dependency dependency : toDuplicate.getAllDependencies()) {
if (includedBuild(project, dependency.getName()) != null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id 'java'
id 'io.quarkus'
}

group = 'com.quarkus.demo'
version = '1.0'

repositories {
mavenCentral()
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy'

constraints {
implementation 'javax.json.bind:javax.json.bind-api:1.0'
}

implementation 'javax.json.bind:javax.json.bind-api'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pluginManagement {
repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'quarkus-dependency-constraint'


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.acme.quarkus.sample;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkus.gradle;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class DependencyConstraintsTest extends QuarkusGradleWrapperTestBase {

@Test
public void shoudBuildProjectWithDependencyConstraint() throws Exception {
File projectDir = getProjectDir("dependency-constraints-project");

BuildResult buildResult = runGradleWrapper(projectDir, "clean", "quarkusBuild", "-Dquarkus.package.type=mutable-jar");

assertThat(buildResult.getTasks().get(":quarkusBuild")).isEqualTo(BuildResult.SUCCESS_OUTCOME);

final File buildDir = new File(projectDir, "build");
final Path mainLib = buildDir.toPath().resolve("quarkus-app").resolve("lib").resolve("main");

assertThat(mainLib.resolve("javax.json.bind.javax.json.bind-api-1.0.jar")).exists();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.gradle.devmode;

import static org.assertj.core.api.Assertions.assertThat;

public class DependencyConstraintsDevModeTest extends QuarkusDevGradleTestBase {

@Override
protected String projectDirectoryName() {
return "dependency-constraints-project";
}

@Override
protected void testDevMode() throws Exception {
assertThat(getHttpResponse("/hello")).contains("hello");
}
}

0 comments on commit 04801d9

Please sign in to comment.