Created
May 8, 2016 19:58
-
-
Save fikovnik/ffc1fed1867bc7fa679aaf8e48f00c21 to your computer and use it in GitHub Desktop.
Building maven plugins by gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configurations { | |
mavenEmbedder | |
} | |
dependencies { | |
compile "org.apache.maven:maven-core:$mavenVersion" | |
compile "org.apache.maven:maven-plugin-api:$mavenVersion" | |
compile 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.4' | |
mavenEmbedder "org.apache.maven:maven-embedder:$mavenVersion" | |
mavenEmbedder 'org.slf4j:slf4j-simple:1.7.5' | |
mavenEmbedder 'org.eclipse.aether:aether-connector-basic:1.0.2.v20150114' | |
mavenEmbedder 'org.eclipse.aether:aether-transport-wagon:1.0.2.v20150114' | |
mavenEmbedder 'org.apache.maven.wagon:wagon-http:2.9:shaded' | |
mavenEmbedder 'org.apache.maven.wagon:wagon-provider-api:2.9' | |
} | |
install.repositories.mavenInstaller.pom.with { | |
groupId = project.group | |
artifactId = project.name | |
version = project.version | |
packaging = 'maven-plugin' | |
} | |
// runs the plugin description generator | |
task generatePluginDescriptor(type: JavaExec, dependsOn: compileJava) { | |
def pomFile = file("$buildDir/pom.xml") | |
def pluginDescriptorFile = new File(project.compileJava.destinationDir, 'META-INF/maven/plugin.xml') | |
def directory = buildDir.canonicalPath | |
def outputDirectory = compileJava.destinationDir.canonicalPath | |
// FIXME: this does not seem to be working | |
inputs.files project.compileJava.outputs.files | |
outputs.file pluginDescriptorFile | |
classpath = configurations.mavenEmbedder | |
main = 'org.apache.maven.cli.MavenCli' | |
systemProperties['maven.multiModuleProjectDirectory'] = projectDir | |
args = [ | |
'--errors', | |
'--batch-mode', | |
'--settings', '../config/repo-settings.xml', | |
'--file', "${buildDir}/pom.xml", | |
'org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor' | |
] | |
doFirst { | |
// we have to do it in this cryptic way, instead of | |
// ``` | |
// project { | |
// build { | |
// directory = directory | |
// outputDirectory = outputDirectory | |
// } | |
// } | |
// because MavenModel already defines build and so it will | |
// result in No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model | |
install.repositories | |
.mavenInstaller | |
.pom | |
.withXml { | |
asNode().appendNode('build') | |
.with { | |
appendNode('directory', directory) | |
appendNode('outputDirectory', outputDirectory) | |
} | |
} | |
.writeTo(pomFile) | |
assert pomFile.file, "${pomFile.canonicalPath}: was not generated" | |
logger.info("POM is generated in ${pomFile.canonicalPath}") | |
} | |
doLast { | |
assert pluginDescriptorFile.file, "${pluginDescriptorFile.canonicalPath}: was not generated" | |
logger.info("Plugin descriptor is generated in ${pluginDescriptorFile.canonicalPath}") | |
} | |
} | |
project.jar.dependsOn(generatePluginDescriptor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And what should be in
../config/repo-settings.xml
?