From b946b5e2da450ec9615903dc581db521a52f9b46 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Fri, 31 Jan 2014 11:39:02 -0500 Subject: [PATCH] HHH-8777 dynamically generate descriptor dependencies Conflicts: .gitignore hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml.original tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml --- .gitignore | 1 + .../hibernate-enhance-maven-plugin.gradle | 75 ++++++++++++------- .../maven/{plugin.xml => plugin.xml.original} | 53 +------------ 3 files changed, 53 insertions(+), 76 deletions(-) rename tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/{plugin.xml => plugin.xml.original} (71%) diff --git a/.gitignore b/.gitignore index 93d26538c5..b28d3d6e79 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ ObjectStore # Maven Enhance Plugin tooling/hibernate-enhance-maven-plugin/src/main/resources/pom.xml +tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml diff --git a/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle b/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle index 0b6966a4cc..68c47ada48 100644 --- a/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle +++ b/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle @@ -1,6 +1,8 @@ apply plugin: 'java' apply plugin: 'maven' +import org.apache.tools.ant.filters.ReplaceTokens + group = 'org.hibernate.orm.tooling' repositories { @@ -17,33 +19,17 @@ processResources.doLast { } dependencies { - compile( libraries.maven_plugin ) { - transitive = false - } - compile( libraries.maven_plugin_tools ) { - transitive = false - } - compile( project(':hibernate-core') ) { - transitive = false - } - compile( libraries.jpa ){ - transitive = false - } - compile( libraries.javassist ){ - transitive = false - } + compile( libraries.maven_plugin ) { transitive = false } + compile( libraries.maven_plugin_tools ) { transitive = false } + compile( project(':hibernate-core') ) { transitive = false } + compile( libraries.jpa ) { transitive = false } + compile( libraries.javassist ) { transitive = false } compile 'org.codehaus.plexus:plexus-utils:3.0.1' - - runtime( libraries.maven_plugin ) { - } - runtime( libraries.maven_plugin_tools ) { - } - runtime( project(':hibernate-core') ) { - } - runtime( libraries.jpa ){ - } - runtime( libraries.javassist ){ - } + runtime( libraries.maven_plugin ) + runtime( libraries.maven_plugin_tools ) + runtime( project(':hibernate-core') ) + runtime( libraries.jpa ) + runtime( libraries.javassist ) runtime 'org.codehaus.plexus:plexus-utils:3.0.1' } @@ -51,7 +37,41 @@ dependencies { configurations.remove(configurations.getByName('testCompile')) configurations.remove(configurations.getByName('testRuntime')) -task writeNewPom(type:Task, description: 'Writes pom.xml using merged Gradle dependency and MavenPom configuration.') { +// 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.original" + into "src/main/resources/META-INF/maven" + rename ("plugin.xml.original", "plugin.xml") + filter(ReplaceTokens, tokens: ['generated-dependencies' :\ + generateMavenDependency(libraries.jpa)\ + + generateMavenDependency(libraries.antlr)\ + + generateMavenDependency(libraries.dom4j)\ + + generateMavenDependency(libraries.jta)\ + + generateMavenDependency(libraries.commons_annotations)\ + + generateMavenDependency(libraries.javassist)\ + + 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 \ + ""\ + + "" + split[0] + ""\ + + "" + split[1] + ""\ + + "jar"\ + + "" + split[2] + ""\ + + "\n" +} + +task writeNewPom(type:Task, description: 'Writes pom.xml using merged Gradle dependency and MavenPom configuration.') { ext.pomDefinition = pom { project { groupId project.group @@ -85,5 +105,6 @@ task writeNewPom(type:Task, description: 'Writes pom.xml using merged Gradle dep ext.pomDefinition.writeTo("$projectDir/src/main/resources/pom.xml") } +writeNewPom.dependsOn processPluginXml processResources.dependsOn writeNewPom diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml.original similarity index 71% rename from tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml rename to tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml.original index ea4d1d4096..08aea62758 100644 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml +++ b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml.original @@ -44,12 +44,9 @@ - - org.jboss.logging - jboss-logging - jar - 3.1.0.GA - + + @generated-dependencies@ + org.codehaus.plexus plexus-utils @@ -68,42 +65,6 @@ jar 3.0 - - org.hibernate - hibernate-core - jar - 4.2.8.Final - - - antlr - antlr - jar - 2.7.7 - - - dom4j - dom4j - jar - 1.6.1 - - - org.jboss.spec.javax.transaction - jboss-transaction-api_1.1_spec - jar - 1.0.1.Final - - - org.hibernate.common - hibernate-commons-annotations - jar - 4.0.2.Final - - - org.hibernate.javax.persistence - hibernate-jpa-2.0-api - jar - 1.0.1.Final - org.apache.maven maven-plugin-api @@ -152,11 +113,5 @@ jar 0.9.9 - - org.javassist - javassist - jar - 3.18.1-GA - - \ No newline at end of file +