Skip to content

Commit

Permalink
#16 - Untangled build execution for Artifactory and Maven Central.
Browse files Browse the repository at this point in the history
As the Artifactory Maven plugin currently doesn't deploy GPG signatures we need to separate the release build into two iterations. The first one is building the artifacts and promoting them to Artifactory. The second one signs the artifacts and uploads them to Maven Central in case we release a public version (GA or service release).
  • Loading branch information
odrotbohm committed Apr 5, 2016
1 parent 5451682 commit 76aa9e8
Showing 1 changed file with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -244,32 +244,71 @@ public DeploymentInformation deploy(ModuleIteration module) {

DeploymentInformation information = new DeploymentInformation(module, properties);

deployToArtifactory(module, information);
deployToMavenCentral(module);

return information;
}

/**
* Triggers Maven commands to deploy module artifacts to Spring Artifactory.
*
* @param module must not be {@literal null}.
* @param information must not be {@literal null}.
*/
private void deployToArtifactory(ModuleIteration module, DeploymentInformation information) {

Assert.notNull(module, "Module iteration must not be null!");
Assert.notNull(information, "Deployment information must not be null!");

logger.log(module, "Deploying artifacts to Spring Artifactory…");

List<String> arguments = new ArrayList<>();
arguments.add("clean");
arguments.add("deploy");
arguments.add("-Pci,release".concat(module.getIteration().isPublic() ? ",central" : ""));

arguments.add("-Pci,release");
arguments.add("-DskipTests");

arguments.add("-Dartifactory.server=".concat(properties.getServer().getUri()));
arguments.add("-Dartifactory.staging-repository=".concat(properties.getStagingRepository()));
arguments.add("-Dartifactory.username=".concat(properties.getUsername()));
arguments.add("-Dartifactory.password=".concat(properties.getPassword()));
arguments.add("-Dartifactory.build-name=\"".concat(information.getBuildName()).concat("\""));
arguments.add("-Dartifactory.build-number=".concat(information.getBuildNumber()));

if (module.getIteration().isPublic()) {
mvn.execute(module.getProject(), arguments);
}

Gpg gpg = properties.getGpg();
/**
* Triggers Maven commands to deploy to Sonatypes OSS Nexus if the given {@link ModuleIteration} refers to a version
* that has to be publically released.
*
* @param module must not be {@literal null}.
*/
private void deployToMavenCentral(ModuleIteration module) {

Assert.notNull(module, "Module iteration must not be null!");

arguments.add("-Dgpg.executable=".concat(gpg.getExecutable()));
arguments.add("-Dgpg.keyname=".concat(gpg.getKeyname()));
arguments.add("-Dgpg.password=".concat(gpg.getPassword()));
if (!module.getIteration().isPublic()) {

logger.log(module, "Skipping deployment to Maven Central as it's not a public version!");
return;
}

mvn.execute(module.getProject(), arguments);
logger.log(module, "Deploying artifacts to Sonatype OSS Nexus…");

return information;
List<String> arguments = new ArrayList<>();
arguments.add("deploy");
arguments.add("-Pci,central");
arguments.add("-DskipTests");

Gpg gpg = properties.getGpg();

arguments.add("-Dgpg.executable=".concat(gpg.getExecutable()));
arguments.add("-Dgpg.keyname=".concat(gpg.getKeyname()));
arguments.add("-Dgpg.password=".concat(gpg.getPassword()));

mvn.execute(module.getProject(), arguments);
}

/*
Expand All @@ -289,6 +328,9 @@ private void execute(File file, Consumer<Pom> callback) {
execute(file, Pom.class, callback);
}

/**
* TODO: Move XML file callbacks using the {@link ProjectionFactory} to {@link Workspace}.
*/
private <T extends Pom> void execute(File file, Class<T> type, Consumer<T> callback) {

XBFileIO io = projectionFactory.io().file(file);
Expand Down

0 comments on commit 76aa9e8

Please sign in to comment.