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

113 lines
3.9 KiB
Groovy

apply plugin: 'java'
apply plugin: 'maven'
import org.apache.tools.ant.filters.ReplaceTokens
group = 'org.hibernate.orm.tooling'
repositories {
mavenCentral()
}
processResources.doLast {
project.build.outputDirectory = '${project.build.outputDirectory}'
copy {
from 'src/main/resources'
into processResources.destinationDir
expand ([ version: version, project: project, dir: '${dir}' ])
}
}
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 '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 'org.codehaus.plexus:plexus-utils:3.0.1'
}
// 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 \
"<dependency>"\
+ "<groupId>" + split[0] + "</groupId>"\
+ "<artifactId>" + split[1] + "</artifactId>"\
+ "<type>jar</type>"\
+ "<version>" + split[2] + "</version>"\
+ "</dependency>\n"
}
task writeNewPom(type:Task, description: 'Writes pom.xml using merged Gradle dependency and MavenPom configuration.') {
ext.pomDefinition = pom {
configurations {
// avoiding test dependencies in generated pom
compile
runtime
}
project {
groupId project.group
packaging 'maven-plugin'
name 'Enhance Plugin of the Hibernate project for use with Maven build system.'
build {
plugins {
plugin {
groupId 'org.apache.maven.plugins'
artifactId 'maven-plugin-plugin'
version '3.2'
configuration {
skipErrorNoDescriptorsFound 'true'
}
executions {
execution {
id 'mojo-descriptor'
goals {
goal 'descriptor'
}
}
}
}
}
}
properties {
'project.build.sourceEncoding' 'UTF-8'
}
}
}
ext.pomDefinition.writeTo("$projectDir/src/main/resources/pom.xml")
}
writeNewPom.dependsOn processPluginXml
processResources.dependsOn writeNewPom