From f6346b0606d6238e31d5b321aaceeaf236b59b43 Mon Sep 17 00:00:00 2001
From: Nikolaus Krismer <niko@krismer.de>
Date: Fri, 21 Mar 2014 21:51:08 +0100
Subject: [PATCH] fixed problems when releasing to nexus repository

---
 build.gradle | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/build.gradle b/build.gradle
index f51aeae6..36770332 100644
--- a/build.gradle
+++ b/build.gradle
@@ -48,7 +48,6 @@ targetCompatibility=1.7
  * "Building RELEASE version 0.2.3")
  */
 
-
 ext {
 	isRelease = false
 }
@@ -72,15 +71,32 @@ gradle.taskGraph.whenReady {taskGraph ->
 
 	if (version.endsWith('-SNAPSHOT')) {
 		println "Building SNAPSHOT version $version"
-		cargo.deployable {
-			context = 'testing'
-		}
 	} else {
-		isRelease = true;
 		println "Building RELEASE version $version"
-		cargo.deployable {
-			context = 'isochrone'
-		}
+		isRelease = true;
+	}
+
+	// fixed lazy versioning for cargo plugin
+	cargo.deployable {
+		context = "${isRelease ? 'isochrone' : 'testing'}"
+	}
+
+	// fixes lazy versioning for maven-publish plugin
+	project.tasks.withType(PublishToMavenRepository) { publishTask ->
+		def oldArtifacts = publishTask.publication.artifacts.toArray()
+		publishTask.publication.artifacts.clear()
+		oldArtifacts.each({ artifact ->
+			publishTask.publication.artifacts.artifact(
+				source: artifact.file.getAbsolutePath().replaceAll(publishTask.publication.version, project.version),
+				classifier: artifact.classifier,
+				extension: artifact.extension
+			)
+		})
+		publishTask.repository.url repositoryPrefix + "${isRelease ? 'releases' : 'snapshots'}"
+		publishTask.publication.version = project.version
+	}
+	project.tasks.withType(GenerateMavenPom).each { generateMavenPomTask ->
+		generateMavenPomTask.pom.getProjectIdentity().version = project.version
 	}
 }
 
@@ -156,7 +172,7 @@ cargo {
 	containerId = cargoContainer
 	port = cargoPort as int
 
-	// deployable part is set by versioning above
+	// deployable block is set by versioning above
 
 	remote {
 		hostname = cargoHostname
@@ -270,7 +286,7 @@ publishing {
 				username repositoryUsername
 				password repositoryPassword
 			}
-			url repositoryPrefix + "${isRelease ? 'releases' : 'snapshots'}"
+			// url is configured in versioning part
 		}
 	}
 }
-- 
GitLab