Skip to content
Open
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 @@ -117,6 +117,21 @@ class PropertyNameCalculator {
possibleKey = lastIndex > 0 ? possibleKey.substring(0, lastIndex) : null
}

// Fallback: check if any existing version property is a prefix of the artifact key.
// This handles cases like 'derbyclient' matching 'derby.version' to align with
// Spring Boot's BOM property naming conventions.
String artifactKey = keyMappings[found.coordinates]
if (artifactKey) {
String match = versions.keySet()
.findAll { it.endsWith('.version') }
.collect { it - '.version' }
.findAll { artifactKey.startsWith(it) }
.max { it.length() }
if (match) {
return "${match}.version" as String
}
}

null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class CompilePlugin implements Plugin<Project> {
}

private static void configureJavaVersion(Project project) {
Integer javaVersion = lookupPropertyByType(project, 'javaVersion', Integer)
project.tasks.withType(JavaCompile).configureEach {
it.options.release.set(lookupPropertyByType(project, 'javaVersion', Integer))
it.options.release.set(javaVersion)
}
}

Expand Down
11 changes: 10 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,23 @@ ext {
// grails-micronaut-bom project. Declared with `strictly` in the BOM project so
// they win over Micronaut platform's higher versions when consumers use
// enforcedPlatform(:grails-micronaut-bom).
else if (project.name == 'grails-micronaut-bom') {
else if (project.name in ['grails-micronaut-bom', 'grails-hibernate5-micronaut-bom']) {
customBomVersions = [
'liquibase-hibernate.version': '4.27.0',
'liquibase.version' : '4.27.0',
'hibernate.version' : '5.6.15.Final',
'groovy.version' : '5.0.5',
'spock.version' : '2.4-groovy-5.0',
'protobuf.version': '4.30.2',
]
combinedVersions += customBomVersions
customBomDependencies = [
'liquibase' : "org.liquibase:liquibase:${combinedVersions['liquibase.version']}",
'liquibase-cdi' : "org.liquibase:liquibase-cdi:${combinedVersions['liquibase.version']}",
'liquibase-core' : "org.liquibase:liquibase-core:${combinedVersions['liquibase.version']}",
'liquibase-hibernate' : "org.liquibase.ext:liquibase-hibernate5:${combinedVersions['liquibase-hibernate.version']}",
'hibernate-core-jakarta': "org.hibernate:hibernate-core-jakarta:${combinedVersions['hibernate.version']}",
'hibernate-ehcache' : "org.hibernate:hibernate-ehcache:${combinedVersions['hibernate.version']}",
'groovy' : "org.apache.groovy:groovy:${combinedVersions['groovy.version']}",
'groovy-ant' : "org.apache.groovy:groovy-ant:${combinedVersions['groovy.version']}",
'groovy-astbuilder' : "org.apache.groovy:groovy-astbuilder:${combinedVersions['groovy.version']}",
Expand Down
11 changes: 9 additions & 2 deletions gradle/publish-root-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def publishedProjects = [
'grails-base-bom',
'grails-bom',
'grails-hibernate5-bom',
'grails-micronaut-bom',
'grails-bootstrap',
'grails-cache',
'grails-codecs',
Expand Down Expand Up @@ -68,7 +67,6 @@ def publishedProjects = [
'grails-interceptors',
'grails-layout',
'grails-logging',
'grails-micronaut',
'grails-mimetypes',
'grails-rest-transforms',
'grails-scaffolding',
Expand Down Expand Up @@ -143,6 +141,15 @@ def publishedProjects = [
'grails-profiles-web-plugin',
]

def skipMicronautProjects = providers.gradleProperty('skipMicronautProjects').isPresent()
if (!skipMicronautProjects) {
publishedProjects.addAll([
'grails-hibernate5-micronaut-bom',
'grails-micronaut',
'grails-micronaut-bom',
])
}

subprojects {
if (name in publishedProjects) {
// This has to be applied here in the root project due to the nexus plugin requirements
Expand Down
7 changes: 7 additions & 0 deletions gradle/test-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ tasks.withType(Test).configureEach {

useJUnitPlatform()
jvmArgs += java17moduleReflectionCompatibilityArguments
// develocity {
// testRetry {
// maxRetries = configuredTestParallel == 1 ? 1 : 2
// maxFailures = 20
// failOnPassedAfterRetry = true
// }
// }
Comment thread
jamesfredley marked this conversation as resolved.
Outdated
testLogging {
events('passed', 'skipped', 'failed')
showExceptions = true
Expand Down
254 changes: 254 additions & 0 deletions grails-bom/hibernate5-micronaut/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.grails.gradle.tasks.bom.ExtractDependenciesTask
import org.apache.grails.gradle.tasks.bom.ExtractedDependencyConstraint
import org.apache.grails.gradle.tasks.bom.PropertyNameCalculator

buildscript {
apply from: rootProject.layout.projectDirectory.file('dependencies.gradle')
}

plugins {
id 'java-platform'
id 'org.apache.grails.buildsrc.publish'
id 'org.apache.grails.buildsrc.sbom'
}

version = projectVersion
group = 'org.apache.grails'

javaPlatform {
allowDependencies()
}

ext {
isReleaseBuild = System.getenv('GRAILS_PUBLISH_RELEASE') == 'true'
isPublishedExternal = System.getenv().containsKey('NEXUS_PUBLISH_STAGING_PROFILE_ID')
// TODO: It should be possible to pull these build names using includedBuild, but I haven't found a way to do so
gradleBuildProjects = [
'grails-gradle-plugins':'org.apache.grails',
'grails-gradle-model':'org.apache.grails.gradle',
'grails-gradle-common':'org.apache.grails.gradle',
'grails-gradle-tasks':'org.apache.grails',
]
}

// Register the Micronaut platform in combinedPlatforms/combinedVersions so
// PropertyNameCalculator (used by extractConstraints and pomCustomization) can
// resolve a property name for the micronaut-platform constraint.
project.ext.combinedPlatforms = combinedPlatforms + ['micronaut-platform': "io.micronaut.platform:micronaut-platform:$micronautPlatformVersion".toString()]
project.ext.combinedVersions = combinedVersions + ['micronaut-platform.version': micronautPlatformVersion as String]

// Coordinates we override via customBomDependencies — these must be excluded from the
// inherited platform chain so they don't conflict with our strictly-versioned overrides
// when consumers apply this BOM via enforcedPlatform.
def overriddenModules = customBomDependencies.values().collect { String coord ->
def parts = coord.split(':')
[group: parts[0], module: parts[1]]
}
Set<String> overriddenCoords = overriddenModules.collect { "${it.group}:${it.module}".toString() } as Set

dependencies {
api(platform(project(':grails-base-bom'))) {
overriddenModules.each { ovr ->
exclude group: ovr.group, module: ovr.module
}
}

// Re-export the Micronaut platform so consumers inherit Micronaut's managed versions
// transitively. Exclude Groovy since we declare the required version explicitly via
// customBomDependencies. Exclude Spock since we manage that version ourselves.
api(platform("io.micronaut.platform:micronaut-platform:$micronautPlatformVersion")) {
exclude group: 'org.apache.groovy'
exclude group: 'org.spockframework'
}

constraints {
// Re-declare base BOM constraints directly so enforcedPlatform() consumers
// get forced versions. Constraints inherited via platform() are not enforced
// by enforcedPlatform — only direct constraints are.
// Skip entries we override below in customBomDependencies to avoid conflicting
// strictly constraints under enforcedPlatform.
gradleBomDependencies.values().each { String coord ->
def parts = coord.split(':')
String key = parts[0] + ':' + parts[1]
if (key in overriddenCoords) {
return
}
api coord
}
bomDependencies.values().each { String coord ->
def parts = coord.split(':')
String key = parts[0] + ':' + parts[1]
if (key in overriddenCoords) return
api coord
}
for (def entry : bomPlatformDependencies.entrySet()) {
api entry.value
}
// Re-declare the Micronaut platform as a constraint for enforcedPlatform support
api "io.micronaut.platform:micronaut-platform:$micronautPlatformVersion"
for (def entry : customBomDependencies.entrySet()) {
def parts = entry.value.split(':')
if (parts.length == 3) {
api("${parts[0]}:${parts[1]}") {
version {
strictly parts[2]
}
}
} else {
api entry.value
}
}
}
}

configurations.register('bomDependencies').configure {
it.canBeResolved = true
it.transitive = true
it.extendsFrom(configurations.named('api').get())
}

tasks.register('extractConstraints', ExtractDependenciesTask).configure { ExtractDependenciesTask it ->
it.captureProjectServices(project.dependencies, project.configurations)
it.configuration = configurations.named('bomDependencies')
it.configurationName = 'bomDependencies'
it.destination = project.layout.buildDirectory.file('grails-hibernate5-micronaut-bom-constraints.adoc')
it.platformDefinitions = combinedPlatforms
it.definitions = combinedDependencies
it.projectName = project.name
it.versions = combinedVersions
// Micronaut's platform imports many sub-BOMs (micronaut-*-bom, netty-bom, etc.) that are
// not explicitly registered in dependencies.gradle. Auto-register them so extractConstraints
// can document their versions without requiring manual entries for every transitive platform.
// this is required because the micronaut bom format uses gradle modules instead of a pom like spring boot
it.autoRegisterTransitivePlatforms = true
rootProject.subprojects.each { p ->
evaluationDependsOn(p.path)
}
it.projectArtifactIds.set(project.provider {
Map<String, String> artifactIdMappings = [:]

rootProject.subprojects.each { p ->
artifactIdMappings[p.name] = p.findProperty('pomArtifactId') ?: p.name
}

for (Map.Entry<String, String> dependency : project.ext.gradleBuildProjects.entrySet()) {
artifactIdMappings[dependency.key] = dependency.key
}

artifactIdMappings
})
it.forcedGroupPrefixes.set(['org.apache.grails.profiles': 'grails-profile'])
it.projectCoordinateProperties.set(project.provider {
Map<String, String> projectCoordinates = [:]

rootProject.subprojects.each { p ->
String artifactId = p.findProperty('pomArtifactId') as String ?: p.name
String baseVersionName = artifactId.replaceAll('[.]', '-')
projectCoordinates["${p.group}:${artifactId}:${p.version}" as String] = baseVersionName
}

for (Map.Entry<String, String> dependency : project.ext.gradleBuildProjects.entrySet()) {
projectCoordinates["${dependency.value}:${dependency.key}:${project.version}" as String] = dependency.key
}

projectCoordinates
})

it.dependsOn(project.tasks.named('generateMetadataFileForMavenPublication'), project.tasks.named('generatePomFileForMavenPublication'))
}

def validateNoSnapshotDependencies = tasks.register('validateNoSnapshotDependencies')
validateNoSnapshotDependencies.configure { Task it ->
it.group = 'publishing'
it.description = 'Validates that no snapshot dependencies are present in the project when performing a release.'

it.doLast {
configurations.each { config ->
config.allDependencies.each { dep ->
if (dep.version && dep.version.contains('-SNAPSHOT')) {
throw new GradleException("Releases cannot have a snapshot dependency: ${dep.group}:${dep.name} (${dep.version})")
}
}
}
}
}

if (ext.isReleaseBuild && ext.isPublishedExternal) {
project.afterEvaluate {
tasks.named('generateMetadataFileForMavenPublication').configure {
dependsOn(validateNoSnapshotDependencies)
}
tasks.named('generatePomFileForMavenPublication').configure {
dependsOn(validateNoSnapshotDependencies)
}
}
}

ext {
pomDescription = 'Grails Hibernate 5 Micronaut BOM (Bill of Materials) for Grails projects integrating with Micronaut and Hibernate 5. Layers Hibernate 5 dependency management on top of grails-micronaut-bom; consume as enforcedPlatform.'
pomCustomization = { xml ->
def root = xml.asNode()

def propertiesNode = root.properties ? root.properties[0] : root.appendNode('properties')

def depMgmt = root.dependencyManagement?.getAt(0)
def deps = depMgmt?.dependencies?.getAt(0)
if (deps) {
PropertyNameCalculator propertyNameCalculator = new PropertyNameCalculator(combinedPlatforms, combinedDependencies, combinedVersions)
propertyNameCalculator.addForcedGroupPrefix('org.apache.grails.profiles', 'grails-profile')
propertyNameCalculator.addProjects(rootProject.subprojects)
for (String gradleArtifactId : project.ext.gradleBuildProjects) {
propertyNameCalculator.addProject('org.apache.grails.gradle', gradleArtifactId, project.version as String, gradleArtifactId)
}

Map<String, String> pomProperties = [:]
deps.dependency.each { dep ->
String groupId = dep.groupId.text().trim()
String artifactId = dep.artifactId.text().trim()
boolean isBom = dep.scope.text().trim() == 'import'

String inlineVersion = dep.version.text().trim()
if (inlineVersion == 'null') {
inlineVersion = null
}

if (inlineVersion) {
ExtractedDependencyConstraint extractedConstraint = propertyNameCalculator.calculate(groupId, artifactId, inlineVersion, isBom)
if (extractedConstraint?.versionPropertyReference) {
// use the property reference instead of the hard coded version so that it can be
// overridden by the spring boot dependency management plugin
dep.version[0].value = extractedConstraint.versionPropertyReference

// Add an entry in the <properties> node with the actual version number
pomProperties.put(extractedConstraint.versionPropertyName, inlineVersion)
}
} else if (!inlineVersion) {
throw new GradleException("Dependency $groupId:$artifactId does not have a version.")
}
}

for (Map.Entry<String, String> property : pomProperties.entrySet()) {
propertiesNode.appendNode(property.key, property.value)
}
}
}
}
7 changes: 3 additions & 4 deletions grails-bom/micronaut/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ dependencies {
}
}

// Re-export the Micronaut platform so consumers of grails-micronaut-bom inherit Micronaut's
// managed versions transitively and don't need to declare the platform themselves.
// Exclude Groovy since we declare the required version explicitly below via customBomDependencies.
// Exclude Spock since the base BOM manages that version.
// Re-export the Micronaut platform so consumers inherit Micronaut's managed versions
// transitively. Exclude Groovy since we declare the required version explicitly via
// customBomDependencies. Exclude Spock since we manage that version ourselves.
api(platform("io.micronaut.platform:micronaut-platform:$micronautPlatformVersion")) {
exclude group: 'org.apache.groovy'
exclude group: 'org.spockframework'
Expand Down
17 changes: 17 additions & 0 deletions grails-doc/src/en/guide/conf/micronaut.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ dependencies {

The `grails-micronaut-bom` layers Micronaut-specific dependency overrides on top of `grails-bom` and pins the `io.micronaut.platform:micronaut-platform` version it was built against. Applying it as `enforcedPlatform` makes all of its constraints strictly versioned so that no transitive dependency (including Micronaut's own platform) can override them — there is no need to set a `micronautPlatformVersion` Gradle property. See link:{versionsRef}Grails%20BOM%20Micronaut.html[Grails Micronaut BOM Dependencies] for the full list of managed versions.

==== Hibernate-Specific Micronaut BOMs

If your project targets a specific Hibernate version, use the corresponding Hibernate-specific Micronaut BOM instead of the generic `grails-micronaut-bom`:

* `org.apache.grails:grails-hibernate5-micronaut-bom` -- Micronaut + Hibernate 5 (the default). See link:{versionsRef}Grails%20BOM%20Hibernate5%20Micronaut.html[Grails Hibernate 5 Micronaut BOM Dependencies].
Comment thread
jamesfredley marked this conversation as resolved.
Outdated

[source,groovy]
.build.gradle - Hibernate 5 with Micronaut
----
dependencies {
implementation enforcedPlatform("org.apache.grails:grails-hibernate5-micronaut-bom:$grailsVersion")
implementation 'org.apache.grails:grails-micronaut'
}
----

The generic `grails-micronaut-bom` remains available and currently tracks the Hibernate 5 default. If the framework changes its default Hibernate version in the future, `grails-micronaut-bom` will follow the new default while the Hibernate-specific BOMs remain pinned.

When the `grails-micronaut` plugin is present, the Grails Gradle plugin will automatically apply the required annotation processors to your project and validate that `grails-micronaut-bom` is applied as `enforcedPlatform`. The validation fails the build at configuration time with an actionable error if the BOM is missing or applied as plain `platform(...)`.
Comment thread
jamesfredley marked this conversation as resolved.
Outdated

==== Disabling the Micronaut Auto-Setup
Expand Down
Loading
Loading