diff --git a/build.gradle b/build.gradle
index a7b20ea84..5ec9b01eb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,10 @@
import com.sdl.dxa.builder.maven.MavenBuildTask
import com.sdl.dxa.builder.maven.MavenHelpTask
+import groovy.xml.DOMBuilder
+import groovy.xml.XmlUtil
+import groovy.xml.dom.DOMCategory
+
+apply plugin: 'groovy'
buildscript {
repositories {
@@ -20,25 +25,50 @@ task wrapper(type: Wrapper) {
task help(type: MavenHelpTask)
-task buildDxa(type: MavenBuildTask) {
+task buildFramework(type: MavenBuildTask) {
configurations = [
["dxa-bom"],
["dxa-bom-2013sp1", "dxa-bom-modules"],
["dxa-framework"],
["> dxa-webapp > clean archetype:create-from-project -Darchetype.properties=archetype.properties"]
]
+}
+
+task prepareArchetype(dependsOn: buildFramework) << {
+ def from = file("${project.projectDir}/dxa-webapp/target/generated-sources/archetype/src/main/resources/archetype-resources/pom.xml")
+ def to = file("${project.projectDir}/dxa-webapp/target/generated-sources/archetype/pom.xml")
+
+ def docFrom = DOMBuilder.parse(new FileReader(from), false, true, true)
+ def docTo = DOMBuilder.parse(new FileReader(to), false, true, true)
- // special hook for archetypes as id does not inherit nor sections,
- // but we still need to sign artifact in case of release
- if (project.hasProperty('command') && project.command =~ /.*-P(.*\b)?release\b.*/) {
- configurations << ["> dxa-webapp/target/generated-sources/archetype > ${project.command} " +
- "org.apache.maven.plugins:maven-gpg-plugin:sign " +
- "org.apache.maven.plugins:maven-source-plugin:jar-no-fork " +
- "org.apache.maven.plugins:maven-javadoc-plugin:jar"]
- } else {
- configurations << ["dxa-webapp/target/generated-sources/archetype"]
+ def rootFrom = docFrom.documentElement
+ def rootTo = docTo.documentElement
+
+ def parentTag = rootFrom.getElementsByTagName('parent').item(0)
+
+ use(DOMCategory) {
+ def importNode = docTo.importNode(parentTag, true)
+ rootTo.insertBefore(importNode, rootTo.getFirstChild())
}
+ rootFrom.removeChild(parentTag)
+
+ rootFrom.normalize()
+ rootTo.normalize()
+
+ XmlUtil.serialize rootFrom, from.newPrintWriter()
+ XmlUtil.serialize rootTo, to.newPrintWriter()
+
+ println 'POMs for Archetype have been changed (parent tag moved from archetype itself to its pom)'
+}
+
+task buildArchetype(type: MavenBuildTask, dependsOn: prepareArchetype) {
+ configurations = [["dxa-webapp/target/generated-sources/archetype"]]
+}
+
+task buildDxa(type: MavenBuildTask, dependsOn: [buildFramework, buildArchetype])
+
+def mavenSettings = {
if (project.hasProperty('command')) {
command = project.command
}
@@ -50,4 +80,8 @@ task buildDxa(type: MavenBuildTask) {
if (project.hasProperty('mavenProperties')) {
mavenProperties = project.mavenProperties
}
-}
\ No newline at end of file
+}
+
+buildFramework mavenSettings
+buildArchetype mavenSettings
+buildDxa mavenSettings
diff --git a/dxa-builder/build.gradle b/dxa-builder/build.gradle
index 4e1b1ab54..1f228d3c6 100644
--- a/dxa-builder/build.gradle
+++ b/dxa-builder/build.gradle
@@ -25,14 +25,65 @@ repositories {
}
}
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier "javadoc"
+ from javadoc
+}
+
task sourceJar(type: Jar) {
- classifier "sources"
+ classifier = 'sources'
from sourceSets.main.allSource
}
-task javadocJar(type: Jar) {
- classifier "javadoc"
- from javadoc
+ext {
+ pomFilePath = "${project.buildDir}/pom/pom.xml"
+ pomFile = file(pomFilePath)
+}
+
+configurations {
+ pom
+}
+
+artifacts {
+ archives jar
+ archives sourceJar
+ archives javadocJar
+ pom pomFile
+}
+
+task signPom(type: Sign) {
+ sign configurations.pom
+}
+
+task signJars(type: Sign, dependsOn: [jar, signPom, javadocJar, sourceJar]) {
+ sign configurations.archives
+}
+task preparePublication(dependsOn: [signPom, signJars])
+
+task publishLocal(dependsOn: [build, publishToMavenLocal])
+task publishRemote(dependsOn: [build, preparePublication, publish])
+
+model {
+ tasks.generatePomFileForMavenJavaPublication {
+ destination = project.ext.pomFile
+ }
+ tasks.signJars {
+ dependsOn(generatePomFileForMavenJavaPublication)
+ }
+}
+
+def getSignatureFiles = {
+ def allFiles = project.tasks.signJars.signatureFiles.collect { it }
+ def signedSources = allFiles.find { it.name.contains('-sources') }
+ def signedJavadoc = allFiles.find { it.name.contains('-javadoc') }
+ def signedPom = allFiles.find { it.name.contains('pom.xml') }
+ def signedJar = (allFiles - [signedSources, signedJavadoc, signedPom])[0]
+ return [
+ [archive: signedSources, classifier: 'sources', extension: 'jar.asc'],
+ [archive: signedJavadoc, classifier: 'javadoc', extension: 'jar.asc'],
+ [archive: signedJar, classifier: null, extension: 'jar.asc'],
+ [archive: signedPom, classifier: null, extension: 'pom.asc']
+ ]
}
publishing {
@@ -50,6 +101,7 @@ publishing {
root.appendNode('name', 'DXA Builder')
root.appendNode('description', 'Builder plugin for DXA projects used internally to organize build process')
root.appendNode('packaging', 'jar')
+ root.appendNode('url', 'https://www.sdl.com')
def license = root.appendNode('licenses').appendNode('license')
license.appendNode('name', 'The Apache License, Version 2.0')
@@ -73,6 +125,18 @@ publishing {
scm.appendNode('developerConnection', 'scm:git:git@github.com:sdl/dxa-web-application-java.git')
}
}
+
+ if (isRelease) {
+ gpgs(MavenPublication) {
+ println getSignatureFiles()
+ getSignatureFiles().each { signature ->
+ artifact(signature.archive) {
+ classifier = signature.classifier
+ extension = signature.extension
+ }
+ }
+ }
+ }
}
repositories {
maven {
@@ -106,24 +170,8 @@ publishing {
}
}
-if (isRelease) {
- signing {
- sign configurations.archives
- }
-}
-
dependencies {
compile gradleApi()
compile localGroovy()
testCompile group: 'junit', name: 'junit', version: '4.11'
}
-
-task publishLocal() {
- dependsOn build
- dependsOn publishToMavenLocal
-}
-
-task publishRemote() {
- dependsOn publishLocal
- dependsOn publish
-}
\ No newline at end of file