Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid including platform BOM twice in the Gradle plugin #11255

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,30 @@ protected boolean addDependency(AppArtifactCoords coords, boolean managed) {
}

static boolean addDependencyInModel(Model model, AppArtifactCoords coords, boolean managed) {
StringBuilder newDependency = new StringBuilder()
.append(" implementation '")
.append(coords.getGroupId())
.append(":")
.append(coords.getArtifactId());
boolean isBOM = "pom".equals(coords.getType());
StringBuilder newDependency;
ia3andy marked this conversation as resolved.
Show resolved Hide resolved
if (isBOM) {
// Check if BOM is not included already
String resolvedPlatform = String
.format("%s:%s:%s", getProperty(model, "quarkusPlatformGroupId"),
getProperty(model, "quarkusPlatformArtifactId"),
getProperty(model, "quarkusPlatformVersion"));
String thisBOM = String.format("%s:%s:%s", coords.getGroupId(), coords.getArtifactId(), coords.getVersion());
gastaldi marked this conversation as resolved.
Show resolved Hide resolved
if (thisBOM.equals(resolvedPlatform)) {
// BOM matches the platform, no need to do anything
return false;
}
newDependency = new StringBuilder()
.append(" implementation enforcedPlatform(\"")
.append(thisBOM)
.append("\")'");
} else {
newDependency = new StringBuilder()
.append(" implementation '")
.append(coords.getGroupId())
.append(":")
.append(coords.getArtifactId());
}
if (!managed &&
(coords.getVersion() != null && !coords.getVersion().isEmpty())) {
newDependency.append(":").append(coords.getVersion());
Expand Down Expand Up @@ -109,18 +128,22 @@ protected void removeDependency(AppArtifactKey key) {

@Override
public String getProperty(String propertyName) {
final String property = getModel().getPropertiesContent().getProperty(propertyName);
if (property != null || getModel().getRootPropertiesContent() == null) {
return property;
}
return getModel().getRootPropertiesContent().getProperty(propertyName);
return getProperty(getModel(), propertyName);
}

@Override
public BuildTool getBuildTool() {
return BuildTool.GRADLE;
}

static String getProperty(Model model, String propertyName) {
final String property = model.getPropertiesContent().getProperty(propertyName);
if (property != null || model.getRootPropertiesContent() == null) {
return property;
}
return model.getRootPropertiesContent().getProperty(propertyName);
}

private Model getModel() {
return modelReference.updateAndGet(model -> {
if (model == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public void testAddAndRemoveExtension() throws IOException, URISyntaxException,

final Path build = projectDir.toPath().resolve("build.gradle");
assertThat(build).exists();
assertThat(new String(Files.readAllBytes(build))).contains("implementation 'io.quarkus:quarkus-hibernate-orm'");
assertThat(new String(Files.readAllBytes(build)))
.contains("implementation 'io.quarkus:quarkus-hibernate-orm'")
.doesNotContain("implementation enforcedPlatform('io.quarkus:quarkus-bom:")
.doesNotContain("implementation 'io.quarkus:quarkus-bom:");

runGradleWrapper(projectDir, ":removeExtension", "--extensions=hibernate-orm");
assertThat(new String(Files.readAllBytes(build))).doesNotContain("implementation 'io.quarkus:quarkus-hibernate-orm'");
Expand Down