Skip to content

Commit 42c45e5

Browse files
committed
HHH-19122 - Leverage org.gradlex.maven-plugin-development for hibernate-maven-plugin
1 parent 1b15676 commit 42c45e5

File tree

1 file changed

+7
-70
lines changed

1 file changed

+7
-70
lines changed

tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
plugins {
99
id "local.java-module"
1010
id "local.publishing"
11-
id "org.hibernate.build.maven-embedder"
11+
id "org.gradlex.maven-plugin-development" version "1.0.3"
1212
}
1313

1414
description = 'Maven plugin to integrate aspects of Hibernate into your build.'
@@ -17,9 +17,10 @@ dependencies {
1717
implementation project( ":hibernate-core" )
1818

1919
implementation "org.apache.maven:maven-plugin-api:3.6.3"
20-
implementation "org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0"
2120
implementation "org.apache.maven:maven-project:2.2.1"
2221
implementation "org.apache.maven.shared:file-management:3.1.0"
22+
23+
compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0"
2324
}
2425

2526
def releasePrepareTask = tasks.register("releasePrepare") {
@@ -48,6 +49,9 @@ var publishingExtension = project.getExtensions().getByType(PublishingExtension)
4849
publishingExtension.publications.named("publishedArtifacts") {
4950
from components.java
5051

52+
// Adjust the pom for 3 things:
53+
// 1. set packaging to maven-plugin (org.gradlex.maven-plugin-development does not in my testing)
54+
// 2. scope of org.apache.maven dependencies
5155
pom.withXml {
5256
asNode()
5357
.version
@@ -61,77 +65,10 @@ publishingExtension.publications.named("publishedArtifacts") {
6165
dependency.groupId.text().startsWith('org.apache.maven')
6266
}
6367
.each { dependency ->
64-
if (dependency.groupId.text().startsWith('org.apache.maven.shared')) {
65-
dependency.scope*.value = 'compile'
66-
} else {
68+
if (!dependency.groupId.text().startsWith('org.apache.maven.shared')) {
6769
dependency.scope*.value = 'provided'
6870
}
6971
}
70-
asNode()
71-
.dependencies
72-
.dependency
73-
.findAll { dependency ->
74-
dependency.groupId.text().startsWith('org.hibernate.orm')
75-
}
76-
.each { dependency ->
77-
dependency.scope*.value = 'compile'
78-
}
79-
asNode()
80-
.dependencies
81-
.plus {
82-
def plugins = build().appendNode('plugins')
83-
def pluginPlugin = plugins.appendNode('plugin')
84-
pluginPlugin.appendNode('groupId', 'org.apache.maven.plugins')
85-
pluginPlugin.appendNode('artifactId', 'maven-plugin-plugin')
86-
pluginPlugin.appendNode('version', '3.15.0')
87-
def pluginConfiguration = pluginPlugin.appendNode('configuration')
88-
pluginConfiguration.appendNode('goalPrefix', 'plugin')
89-
pluginConfiguration.appendNode('outputDirectory', layout.buildDirectory.dir('generated/sources/plugin-descriptors/META-INF/maven').get().getAsFile().getAbsolutePath() )
90-
def invokerPlugin = plugins.appendNode('plugin');
91-
invokerPlugin.appendNode('groupId', 'org.apache.maven.plugins')
92-
invokerPlugin.appendNode('artifactId', 'maven-invoker-plugin')
93-
invokerPlugin.appendNode('version', '3.8.0')
94-
def invokerConfiguration = invokerPlugin.appendNode('configuration');
95-
invokerConfiguration.appendNode('debug', 'true');
96-
invokerConfiguration.appendNode('mavenExecutable', 'mvnw');
97-
def scriptVariables = invokerConfiguration.appendNode('scriptVariables');
98-
scriptVariables.appendNode('hibernateCoreJarPath', layout.buildDirectory.file('maven-embedder/maven-local/org/hibernate/orm/hibernate-core/' + project.version + '/hibernate-core-' + project.version + '.jar').get().getAsFile().getAbsolutePath())
99-
}
10072
}
10173
}
10274

103-
// Following tasks need to be performed:
104-
// 1. Compile the Java classes
105-
// 2. Copy the source tree to the working directory
106-
// 3. Copy the compiled Java classes to the working directory
107-
// 4. Install the 'hibernate-core' dependency in the local Maven repo
108-
// 5. Install the 'hibernate-scan-jandex' dependency in the local Maven repo
109-
// 6. Generate the pom.xml file for the Maven plugin
110-
// 7. Generate the Maven plugin descriptor
111-
// 8. Create the jar for the Maven plugin
112-
// 9. Install the Maven plugin descriptor in the local Maven repo
113-
// 10. Run the integration tests
114-
115-
// Prepare the working directory
116-
tasks.register('prepareWorkspace', Copy) {
117-
into('target/maven-embedder/workspace')
118-
// copy the plugin pom
119-
with( copySpec {
120-
from('target/publications/publishedArtifacts/pom-default.xml')
121-
rename('pom-default.xml', 'pom.xml')
122-
dependsOn('generatePomFileForPublishedArtifactsPublication')
123-
})
124-
// copy the compiled java classes
125-
into('target/classes') {
126-
with( copySpec {
127-
from('target/classes/java/main')
128-
dependsOn('compileJava')
129-
})
130-
}
131-
// copy the integration tests
132-
into('src/it') {
133-
with( copySpec {
134-
from('src/it')
135-
})
136-
}
137-
}

0 commit comments

Comments
 (0)