Created
September 13, 2017 06:59
-
-
Save slamdev/fba525a3334b26ecc495eebeb3783f60 to your computer and use it in GitHub Desktop.
maven central compatible pom generation
This file contains hidden or 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
plugins { | |
id 'base' | |
id 'idea' | |
} | |
ext { | |
libs = subprojects.collect { it.name }.findAll { !(it in ['bom', 'modules']) } | |
addRequiredMetadata = this.&addRequiredMetadata | |
} | |
allprojects { | |
group 'com.github.slamdev.microframework' | |
} | |
subprojects { | |
afterEvaluate { module -> | |
if (module.plugins.hasPlugin('io.spring.dependency-management')) { | |
dependencyManagement { | |
dependencies { | |
dependency 'com.google.guava:guava:23.0' | |
dependency 'com.google.code.gson:gson:2.8.1' | |
dependency 'com.squareup.okhttp3:okhttp:3.8.1' | |
dependency 'org.easybatch:easybatch-core:5.1.0' | |
dependency 'org.easybatch:easybatch-jdbc:5.1.0' | |
dependency 'org.easybatch:easybatch-flatfile:5.1.0' | |
dependency 'org.easybatch:easybatch-json:5.1.0' | |
dependency 'io.undertow:undertow-core:1.4.18.Final' | |
dependency 'com.typesafe:config:1.3.1' | |
dependency 'org.slf4j:slf4j-api:1.7.25' | |
dependency 'ch.qos.logback:logback-classic:1.2.3' | |
dependency 'ch.qos.logback:logback-access:1.2.3' | |
dependency 'org.projectlombok:lombok:1.16.18' | |
dependency 'org.jdbi:jdbi:2.78' | |
dependency 'org.flywaydb:flyway-core:4.2.0' | |
dependency 'com.google.guava:guava:23.0' | |
dependency 'com.zaxxer:HikariCP:2.6.3' | |
dependency 'com.h2database:h2:1.4.196' | |
dependency 'org.assertj:assertj-core:3.8.0' | |
dependency 'junit:junit:4.12' | |
dependency 'org.mockito:mockito-core:2.9.0' | |
dependency 'org.postgresql:postgresql:42.1.4' | |
dependency 'org.slf4j:jul-to-slf4j:1.7.25' | |
dependency 'com.jayway.jsonpath:json-path:2.4.0' | |
dependency 'com.google.cloud:google-cloud-storage:1.4.0' | |
} | |
} | |
} | |
if (module.plugins.hasPlugin('maven-publish') && module.plugins.hasPlugin('signing')) { | |
if (module.name != 'bom') { | |
javadoc { | |
source = sourceSets.main.allJava | |
} | |
task sourceJar(type: Jar) { | |
from sourceSets.main.allJava | |
classifier 'sources' | |
} | |
task javadocJar(type: Jar) { | |
from javadoc | |
classifier 'javadoc' | |
} | |
tasks.withType(AbstractPublishToMaven) { task -> | |
task.dependsOn signArchives | |
} | |
artifacts { | |
archives jar | |
archives sourceJar | |
archives javadocJar | |
} | |
signing { | |
sign configurations.archives | |
} | |
publishing { | |
publications { | |
"$project.name"(MavenPublication) { | |
addRequiredMetadata(module, pom) | |
pom.withXml { | |
def pomFile = file("${project.buildDir}/generated-pom.xml") | |
writeTo(pomFile) | |
def pomAscFile = signing.sign(pomFile).signatureFiles[0] | |
artifact(pomAscFile) { | |
classifier = null | |
extension = 'pom.asc' | |
} | |
pomFile.delete() | |
} | |
from components.java | |
artifact sourceJar | |
artifact javadocJar | |
project.tasks.signArchives.signatureFiles.each { | |
artifact(it) { | |
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ | |
if (matcher.find()) { | |
classifier = matcher.group(1) | |
} else { | |
classifier = null | |
} | |
extension = 'jar.asc' | |
} | |
} | |
} | |
} | |
} | |
} | |
publishing { | |
repositories { | |
maven { | |
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2' | |
credentials { | |
username sonatypeUsername | |
password sonatypePassword | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
void addRequiredMetadata(Project currentProject, org.gradle.api.publish.maven.MavenPom pom) { | |
pom.withXml { xml -> | |
def root = xml.asNode() | |
root.children().last() + { | |
resolveStrategy = DELEGATE_FIRST | |
description currentProject.description | |
name currentProject.name | |
url 'https://github.com/slamdev/micro-framework' | |
organization { | |
name 'Slamdev' | |
url 'https://github.com/slamdev' | |
} | |
issueManagement { | |
system 'GitHub' | |
url 'https://github.com/slamdev/micro-framework/issues' | |
} | |
licenses { | |
license { | |
name 'MIT License' | |
url 'https://github.com/slamdev/micro-framework/blob/master/LICENSE' | |
distribution 'repo' | |
} | |
} | |
scm { | |
url 'https://github.com/slamdev/micro-framework/' | |
connection 'scm:git:git://github.com/slamdev/micro-framework.git' | |
developerConnection 'scm:git:ssh://[email protected]/slamdev/micro-framework.git' | |
} | |
developers { | |
developer { | |
id 'slamdev' | |
name 'slamdev' | |
email '[email protected]' | |
timezone '+2' | |
} | |
} | |
} | |
} | |
} | |
----------- | |
plugins { | |
id 'java' | |
id 'maven-publish' | |
id 'com.jfrog.bintray' version '1.7.3' | |
id 'io.spring.dependency-management' version '1.0.3.RELEASE' | |
} | |
signing { | |
sign configurations.archives | |
} | |
publishing { | |
publications { | |
"$project.name"(MavenPublication) { | |
rootProject.addRequiredMetadata(project, pom) | |
pom.withXml { | |
def node = asNode().get('dependencyManagement').first().get('dependencies').first() | |
rootProject.libs.each { | |
def depNode = new Node(node, 'dependency') | |
depNode.appendNode('groupId', group) | |
depNode.appendNode('artifactId', it) | |
depNode.appendNode('version', version) | |
} | |
def pomFile = file("${project.buildDir}/generated-pom.xml") | |
writeTo(pomFile) | |
def pomAscFile = signing.sign(pomFile).signatureFiles[0] | |
pomFile.delete() | |
} | |
artifact('build/generated-pom.xml.asc') { | |
classifier = null | |
extension = 'pom.asc' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment