Skip to content

Commit

Permalink
Merge branch '5.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
melix committed Mar 9, 2022
2 parents c4b3d46 + e9cf48b commit 244ec24
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allprojects {
group = 'io.micronaut.freedom'
version = projectVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'io.micronaut.build.internal.module'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'io.micronaut.build.internal.bom'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'io.micronaut.build.internal.module'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
projectVersion=1.2.3
projectGroup=io.micronaut.freedom
micronautDocsVersion=2.0.0.RC1
micronautVersion=3.2.0
micronautTestVersion=2.3.7
groovyVersion=3.0.8
spockVersion=2.0-groovy-3.0
title=Micronaut BOM test module
projectDesc=BOM and version catalogs
projectUrl=https://micronaut.io
githubSlug=micronaut-projects/micronaut-bom-test-module
developers=Graeme Rocher

# Micronaut core branch for BOM pull requests
githubCoreBranch=3.2.x

bomProperty=micronautBomVersion

org.gradle.caching=true
org.gradle.parallel=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rootProject.name = "freedom"

include "freedom-bom"
include "freedom-foo"
include "freedom-bar"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.gradle.util.GFileUtils
import spock.lang.Specification
import spock.lang.TempDir

import java.nio.file.Files
import java.nio.file.Path

abstract class AbstractFunctionalTest extends Specification {
Expand Down Expand Up @@ -174,4 +175,10 @@ abstract class AbstractFunctionalTest extends Specification {
}
}
}

protected void dumpRepoContents() {
Files.walk(file("build/repo").toPath()).forEach {
println(it.toString())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.micronaut.build.catalogs

import io.micronaut.build.AbstractFunctionalTest
import io.micronaut.build.AbstractFunctionalTest
import spock.lang.Issue

class BomGenerationFunctionalTest extends AbstractFunctionalTest {
def "inlines Micronaut catalogs into the generated catalog"() {
Expand Down Expand Up @@ -99,4 +100,119 @@ micronaut-function-client-aws = {group = "io.micronaut.aws", name = "micronaut-f
micronaut-test-bom-module = {group = "io.micronaut.dummy", name = "micronaut-test-bom-module", version.ref = "micronaut-test-bom-module" }
""".trim()
}

@Issue("https://github.com/micronaut-projects/micronaut-build/issues/284")
def "uses a single version for all subprojects"() {
withSample("multi-project-bom")
settingsFile.text += """rootProject.name = '$rootName' """

when:
run 'publishAllPublicationsToBuildRepository'

then:
def moduleDir = file("build/repo/io/micronaut/freedom/micronaut-freedom-bom/1.2.3")
def catalogFile = new File(moduleDir, "micronaut-freedom-bom-1.2.3.toml")
moduleDir.exists()
catalogFile.exists()
println catalogFile.text
catalogFile.text.trim() == """#
# This file has been generated by Gradle and is intended to be consumed by Gradle
#
[metadata]
format.version = "1.1"
[versions]
micronaut-freedom = "1.2.3"
[libraries]
micronaut-freedom-bar = {group = "io.micronaut.freedom", name = "micronaut-freedom-bar", version.ref = "micronaut-freedom" }
micronaut-freedom-bom = {group = "io.micronaut.freedom", name = "micronaut-freedom-bom", version.ref = "micronaut-freedom" }
micronaut-freedom-foo = {group = "io.micronaut.freedom", name = "micronaut-freedom-foo", version.ref = "micronaut-freedom" }
""".trim()

and:
def pomFile = new File(moduleDir, "micronaut-freedom-bom-1.2.3.pom")
pomFile.exists()
println pomFile.text
pomFile.text.contains """<properties>
<micronaut.freedom.version>1.2.3</micronaut.freedom.version>
</properties>"""
pomFile.text.contains """<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.micronaut.freedom</groupId>
<artifactId>micronaut-freedom-bar</artifactId>
<version>\${micronaut.freedom.version}</version>
</dependency>
<dependency>
<groupId>io.micronaut.freedom</groupId>
<artifactId>micronaut-freedom-foo</artifactId>
<version>\${micronaut.freedom.version}</version>
</dependency>
</dependencies>
</dependencyManagement>"""

where:
rootName << ['freedom', 'freedom-parent']
}

@Issue("https://github.com/micronaut-projects/micronaut-build/issues/284")
def "can explicitly define the main property name"() {
withSample("multi-project-bom")
settingsFile.text += """rootProject.name = '$rootName' """
file("freedom-bom/build.gradle") << """
micronautBom {
propertyName = 'democracy'
}
"""

when:
run 'publishAllPublicationsToBuildRepository'

then:
def moduleDir = file("build/repo/io/micronaut/freedom/micronaut-freedom-bom/1.2.3")
def catalogFile = new File(moduleDir, "micronaut-freedom-bom-1.2.3.toml")
moduleDir.exists()
catalogFile.exists()
println catalogFile.text
catalogFile.text.trim() == """#
# This file has been generated by Gradle and is intended to be consumed by Gradle
#
[metadata]
format.version = "1.1"
[versions]
micronaut-democracy = "1.2.3"
[libraries]
micronaut-freedom-bar = {group = "io.micronaut.freedom", name = "micronaut-freedom-bar", version.ref = "micronaut-democracy" }
micronaut-freedom-bom = {group = "io.micronaut.freedom", name = "micronaut-freedom-bom", version.ref = "micronaut-democracy" }
micronaut-freedom-foo = {group = "io.micronaut.freedom", name = "micronaut-freedom-foo", version.ref = "micronaut-democracy" }
""".trim()

and:
def pomFile = new File(moduleDir, "micronaut-freedom-bom-1.2.3.pom")
pomFile.exists()
println pomFile.text
pomFile.text.contains """<properties>
<micronaut.democracy.version>1.2.3</micronaut.democracy.version>
</properties>"""
pomFile.text.contains """<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.micronaut.freedom</groupId>
<artifactId>micronaut-freedom-bar</artifactId>
<version>\${micronaut.democracy.version}</version>
</dependency>
<dependency>
<groupId>io.micronaut.freedom</groupId>
<artifactId>micronaut-freedom-foo</artifactId>
<version>\${micronaut.democracy.version}</version>
</dependency>
</dependencies>
</dependencyManagement>"""

where:
rootName << ['freedom', 'freedom-parent']
}
}
19 changes: 11 additions & 8 deletions src/main/groovy/io/micronaut/build/MicronautBomPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private void configureBOM(Project project, MicronautBomExtension bomExtension) {
}

private void configureLate(Project project, MicronautBomExtension bomExtension, PublishingExtension publishing, TaskContainer tasks) {
String mainProjectId = bomExtension.getPropertyName().getOrElse(project.getRootProject().getName().replace("-parent", "").replace('-', '.'));
String publishedName = "micronaut-" + project.getName();
String group = String.valueOf(project.getGroup());
Optional<VersionCatalog> versionCatalog = findVersionCatalog(project, bomExtension);
Expand All @@ -193,7 +194,7 @@ private void configureLate(Project project, MicronautBomExtension bomExtension,
);
tasks.named("generateCatalogAsToml", task -> modelConverter.populateModel());
if (bomExtension.getPublishCatalog().get()) {
configureVersionCatalog(project, bomExtension, publishedName, group);
configureVersionCatalog(project, bomExtension, publishedName, group, mainProjectId);
}
publishing.getPublications().named("maven", MavenPublication.class, pub -> {
pub.setArtifactId(publishedName);
Expand Down Expand Up @@ -226,7 +227,7 @@ private void configureLate(Project project, MicronautBomExtension bomExtension,

// Add individual module versions as properties
forEachProject(bomExtension, project, p -> {
String propertyName = "micronaut." + p.getName().replace('-', '.') + ".version";
String propertyName = "micronaut." + mainProjectId + ".version";
String projectGroup = String.valueOf(p.getGroup());
Optional<Node> pomDep = forEachNode(node, DEPENDENCY_PATH)
.filter(n -> childOf(n, "artifactId").text().equals("micronaut-" + p.getName()) &&
Expand All @@ -249,7 +250,7 @@ private void configureLate(Project project, MicronautBomExtension bomExtension,
}));
forEachProject(bomExtension, project, p -> {
project.evaluationDependsOn(p.getPath());
String propertyName = "micronaut." + p.getName().replace('-', '.') + ".version";
String propertyName = "micronaut." + mainProjectId + ".version";
pom.getProperties().put(propertyName, assertVersion(p));
});
});
Expand Down Expand Up @@ -288,8 +289,9 @@ private void configureLate(Project project, MicronautBomExtension bomExtension,
.create(moduleGroup + ":" + moduleName + ":" + moduleVersion)
);

modelConverter.getExtraVersions().put(moduleName, moduleVersion);
modelConverter.getExtraLibraries().put(moduleName, VersionCatalogConverter.library(moduleGroup, moduleName, moduleName));
String mainModuleName = "micronaut-" + mainProjectId.replace('.', '-');
modelConverter.getExtraVersions().put(mainModuleName, moduleVersion);
modelConverter.getExtraLibraries().put(moduleName, VersionCatalogConverter.library(moduleGroup, moduleName, mainModuleName));
});
}

Expand Down Expand Up @@ -352,12 +354,13 @@ private static Optional<VersionCatalog> findVersionCatalog(Project project, Micr
return Optional.ofNullable(versionCatalogsExtension).map(e -> e.named("libs"));
}

private void configureVersionCatalog(Project project, MicronautBomExtension bomExtension, String publishedName, String group) {
private void configureVersionCatalog(Project project, MicronautBomExtension bomExtension, String publishedName, String group, String mainProjectId) {
if (bomExtension.getIncludeBomInCatalog().get()) {
CatalogPluginExtension catalog = project.getExtensions().getByType(CatalogPluginExtension.class);
catalog.versionCatalog(vc -> {
String versionName = publishedName.replace('-', '.');
vc.alias(publishedName).to(group, publishedName).versionRef(versionName);
String mainModuleName = "micronaut-" + mainProjectId;
String versionName = mainModuleName.replace('-', '.');
vc.library(publishedName, group, publishedName).versionRef(versionName);
vc.version(versionName, String.valueOf(project.getVersion()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ public interface MicronautBomExtension {
* @return the ignored aliases
*/
SetProperty<String> getExcludedInlinedAliases();

/**
* Defines the property name of the version of project dependencies,
* in case it cannot be deduced properly from the root project name
* @return the property name
*/
Property<String> getPropertyName();
}

0 comments on commit 244ec24

Please sign in to comment.