hibernate-orm/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plu...

100 lines
4.4 KiB
Groovy

/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
description = 'Enhance Plugin of the Hibernate project for use with Maven build system.'
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
apply plugin: 'maven-publish'
import org.apache.tools.ant.filters.ReplaceTokens
group = 'org.hibernate.orm.tooling'
processResources {
include "**/lifecycle-mapping-metadata.xml"
include "**/plugin-help.xml"
into processResources.destinationDir
filter(ReplaceTokens, tokens: ['version' : project.version])
}
dependencies {
implementation( project(':hibernate-core') ) { transitive = false }
implementation( libraries.jakarta_jpa ) { transitive = false }
implementation( libraries.jakarta_jta ) { transitive = false }
implementation( libraries.maven_core ) { transitive = false }
implementation( libraries.maven_artifact ) { transitive = false }
implementation( libraries.maven_plugin ) { transitive = false }
implementation( libraries.maven_plugin_tools ) { transitive = false }
implementation 'org.codehaus.plexus:plexus-utils:3.0.24'
implementation 'org.sonatype.plexus:plexus-build-api:0.0.7'
runtimeOnly libraries.maven_core
runtimeOnly libraries.maven_artifact
runtimeOnly libraries.maven_plugin
runtimeOnly libraries.maven_plugin_tools
}
// Inject dependencies into plugin.xml
// Note: injecting the full dependency, rather than just the version,
// removing the need to maintain artifact names that might change with upgrades (JPA/JTA API version, etc.)
task processPluginXml(type: Copy) {
// force out-of-date if version changes
inputs.property("version", project.version)
from "src/main/resources/META-INF/maven/plugin.xml"
into "$processResources.destinationDir/META-INF/maven"
filter(ReplaceTokens, tokens: ['version' : project.version, 'generated-dependencies' :\
generateMavenDependency(libraries.jakarta_jpa)\
+ generateMavenDependency(libraries.antlr)\
+ generateMavenDependency(libraries.jakarta_jta)\
+ generateMavenDependency(libraries.commons_annotations)\
+ generateMavenDependency(libraries.byteBuddy)\
+ generateMavenDependency(libraries.logging)\
+ generateMavenDependency("org.hibernate:hibernate-core:" + project.version)])
}
// TODO: There may be a way to do this directly with Gradle's Maven plugin, but it's still incubating
// and I'd rather not rely on it yet.
def generateMavenDependency(String gradleDependency) {
String[] split = gradleDependency.split(":")
return "\n<dependency>"\
+ "\n <groupId>" + split[0] + "</groupId>"\
+ "\n <artifactId>" + split[1] + "</artifactId>"\
+ "\n <version>" + split[2] + "</version>"\
+ "\n <type>jar</type>"\
+ "\n</dependency>"
}
// Writes pom.xml using merged Gradle dependency and MavenPom configuration.
tasks.named('generatePomFileForPublishedArtifactsPublication') {
pom.with {
packaging 'maven-plugin'
name.set('Hibernate Enhance Maven Plugin')
description 'Enhance Plugin of the Hibernate project for use with Maven build system.'
properties.put(
'project.build.sourceEncoding', 'UTF-8'
)
// HHH-9679 --- build in pom{} conflicts with FactoryBuilderSupport#build so we write that portion of XML by hand
withXml {
asNode().appendNode('build').appendNode('plugins').appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-plugin-plugin')
appendNode('version', '3.2')
appendNode('configuration').appendNode('skipErrorNoDescriptorsFound', 'true')
appendNode('executions').appendNode('execution').with {
appendNode('id', 'mojo-descriptor')
appendNode('goals').appendNode('goal', 'descriptor')
}
}
}
}
}
processResources.dependsOn processPluginXml
// We need this filter here, otherwise Gradle or the JUnit Jupiter platform will load classes at a point
// when they are not yet enhanced, leading to test failures
test.include '**/*Test.class'