Skip to content

Instantly share code, notes, and snippets.

@gaganis
Created May 30, 2017 22:23
Show Gist options
  • Save gaganis/fb0a8d1e27bbaf61281b9314a62bd95b to your computer and use it in GitHub Desktop.
Save gaganis/fb0a8d1e27bbaf61281b9314a62bd95b to your computer and use it in GitHub Desktop.
Non working spotless/plugin-maven gradle config file
ext.artifactId = project.artifactIdMaven
ext.version = project.versionMaven
apply from: rootProject.file('gradle/java-setup.gradle')
apply from: rootProject.file('gradle/java-publish.gradle')
apply plugin: 'maven'
configurations {
mavenEmbedder
}
dependencies {
compile project(':lib')
compile project(':lib-extra')
compile "org.apache.maven:maven-core:3.0"
compile "org.apache.maven:maven-plugin-api:3.0"
compile 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.4'
mavenEmbedder "org.apache.maven:maven-embedder:3.0"
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'
testCompile project(':testlib')
testCompile "junit:junit:${VER_JUNIT}"
testCompile "org.assertj:assertj-core:${VER_ASSERTJ}"
testCompile "com.diffplug.durian:durian-testlib:${VER_DURIAN}"
}
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', '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