Modify build publishing
- Add signing plugin - Add nexus publishing plugin - Tweak publish to separate artifactory and nexus for release vs. snapshot/milestone - Remove docs publish from root as antora will have separate publishing system. - Modify ci workflow to use publishArtifacts task which would then pick either artifactory or nexus. - Relates #165
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -51,7 +51,7 @@ jobs:
|
||||
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
|
||||
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
|
||||
run: |
|
||||
./gradlew build artifactoryPublish \
|
||||
./gradlew build publishArtifacts \
|
||||
-PartifactoryUsername="$ARTIFACTORY_USERNAME" \
|
||||
-PartifactoryPassword="$ARTIFACTORY_PASSWORD"
|
||||
docs:
|
||||
|
||||
@@ -28,6 +28,7 @@ dependencies {
|
||||
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.29.0'
|
||||
implementation 'org.antora:gradle-antora-plugin:1.0.0'
|
||||
implementation 'io.spring.gradle.antora:spring-antora-plugin:0.0.1'
|
||||
implementation 'io.github.gradle-nexus:publish-plugin:1.1.0'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
|
||||
@@ -42,7 +42,6 @@ class DocsPlugin implements Plugin<Project> {
|
||||
pluginManager.apply(JavaPlugin.class);
|
||||
pluginManager.apply(JavaLibraryPlugin.class);
|
||||
pluginManager.apply(ManagementConfigurationPlugin.class);
|
||||
pluginManager.apply(SpringMavenPlugin.class);
|
||||
pluginManager.apply(AntoraPlugin.class);
|
||||
pluginManager.apply(GenerateAntoraYmlPlugin.class);
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
|
||||
public class PublishArtifactsPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getTasks().register("publishArtifacts", new Action<Task>() {
|
||||
@Override
|
||||
public void execute(Task publishArtifacts) {
|
||||
publishArtifacts.setGroup("Publishing");
|
||||
publishArtifacts.setDescription("Publish the artifacts to either Artifactory or Maven Central based on the version");
|
||||
if (Utils.isRelease(project)) {
|
||||
publishArtifacts.dependsOn("publishToOssrh");
|
||||
}
|
||||
else {
|
||||
publishArtifacts.dependsOn("artifactoryPublish");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
* Copyright 2022-2023 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.
|
||||
@@ -15,18 +15,10 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.bundling.Zip;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.external.javadoc.CoreJavadocOptions;
|
||||
|
||||
/**
|
||||
* Manages tasks creating zip file for docs and publishing it.
|
||||
@@ -39,59 +31,7 @@ class RootPlugin implements Plugin<Project> {
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(MavenPublishPlugin.class);
|
||||
pluginManager.apply(PublishLocalPlugin.class);
|
||||
pluginManager.apply(SpringNexusPublishPlugin.class);
|
||||
new ArtifactoryConventions().apply(project);
|
||||
Javadoc apiTask = createApiTask(project);
|
||||
Zip zipTask = createZipTask(project);
|
||||
zipTask.dependsOn(apiTask);
|
||||
}
|
||||
|
||||
private Zip createZipTask(Project project) {
|
||||
Zip zipTask = project.getTasks().create("distZip", Zip.class, zip -> {
|
||||
zip.setGroup("Distribution");
|
||||
zip.from("spring-shell-docs/build/docs/asciidoc", copy -> {
|
||||
copy.into("docs");
|
||||
});
|
||||
zip.from("build/api", copy -> {
|
||||
copy.into("api");
|
||||
});
|
||||
});
|
||||
|
||||
project.getRootProject().getAllprojects().forEach(p -> {
|
||||
p.getPlugins().withType(AsciidoctorJPlugin.class, a -> {
|
||||
p.getTasksByName("asciidoctor", false).forEach(t -> {
|
||||
zipTask.dependsOn(t);
|
||||
});;
|
||||
});
|
||||
});
|
||||
|
||||
project.getArtifacts().add("archives", zipTask);
|
||||
return zipTask;
|
||||
}
|
||||
|
||||
private Javadoc createApiTask(Project project) {
|
||||
Javadoc api = project.getTasks().create("api", Javadoc.class, a -> {
|
||||
a.setGroup("Documentation");
|
||||
a.setDescription("Generates aggregated Javadoc API documentation.");
|
||||
a.setDestinationDir(new File(project.getBuildDir(), "api"));
|
||||
CoreJavadocOptions options = (CoreJavadocOptions) a.getOptions();
|
||||
options.source("17");
|
||||
options.encoding("UTF-8");
|
||||
options.addStringOption("Xdoclint:none", "-quiet");
|
||||
});
|
||||
|
||||
project.getRootProject().getSubprojects().forEach(p -> {
|
||||
p.getPlugins().withType(ModulePlugin.class, m -> {
|
||||
JavaPluginConvention java = p.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
SourceSet mainSourceSet = java.getSourceSets().getByName("main");
|
||||
|
||||
api.setSource(api.getSource().plus(mainSourceSet.getAllJava()));
|
||||
|
||||
p.getTasks().withType(Javadoc.class, j -> {
|
||||
api.setClasspath(api.getClasspath().plus(j.getClasspath()));
|
||||
});
|
||||
});
|
||||
});
|
||||
return api;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +45,10 @@ public class SpringMavenPlugin implements Plugin<Project> {
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(MavenPublishPlugin.class);
|
||||
pluginManager.apply(SpringSigningPlugin.class);
|
||||
pluginManager.apply(PublishLocalPlugin.class);
|
||||
pluginManager.apply(PublishAllJavaComponentsPlugin.class);
|
||||
pluginManager.apply(PublishArtifactsPlugin.class);
|
||||
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishExtension;
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
|
||||
import io.github.gradlenexus.publishplugin.NexusRepository;
|
||||
|
||||
public class SpringNexusPublishPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().apply(NexusPublishPlugin.class);
|
||||
NexusPublishExtension nexusPublishing = project.getExtensions().findByType(NexusPublishExtension.class);
|
||||
nexusPublishing.getRepositories().create("ossrh", new Action<NexusRepository>() {
|
||||
@Override
|
||||
public void execute(NexusRepository nexusRepository) {
|
||||
nexusRepository.getNexusUrl().set(URI.create("https://s01.oss.sonatype.org/service/local/"));
|
||||
nexusRepository.getSnapshotRepositoryUrl()
|
||||
.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/"));
|
||||
}
|
||||
});
|
||||
nexusPublishing.getConnectTimeout().set(Duration.ofMinutes(3));
|
||||
nexusPublishing.getClientTimeout().set(Duration.ofMinutes(3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.publish.Publication;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.plugins.signing.SigningExtension;
|
||||
import org.gradle.plugins.signing.SigningPlugin;
|
||||
|
||||
public class SpringSigningPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPluginManager().apply(SigningPlugin.class);
|
||||
project.getPlugins().withType(SigningPlugin.class).all(new Action<SigningPlugin>() {
|
||||
@Override
|
||||
public void execute(SigningPlugin signingPlugin) {
|
||||
boolean hasSigningKey = project.hasProperty("signing.keyId") || project.hasProperty("signingKey");
|
||||
if (hasSigningKey) {
|
||||
sign(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sign(Project project) {
|
||||
SigningExtension signing = project.getExtensions().findByType(SigningExtension.class);
|
||||
signing.setRequired(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
return project.getGradle().getTaskGraph().hasTask("publishArtifacts");
|
||||
}
|
||||
});
|
||||
String signingKeyId = (String) project.findProperty("signingKeyId");
|
||||
String signingKey = (String) project.findProperty("signingKey");
|
||||
String signingPassword = (String) project.findProperty("signingPassword");
|
||||
if (signingKeyId != null) {
|
||||
signing.useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword);
|
||||
} else {
|
||||
signing.useInMemoryPgpKeys(signingKey, signingPassword);
|
||||
}
|
||||
project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(new Action<PublishAllJavaComponentsPlugin>() {
|
||||
@Override
|
||||
public void execute(PublishAllJavaComponentsPlugin publishingPlugin) {
|
||||
PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
|
||||
Publication maven = publishing.getPublications().getByName("mavenJava");
|
||||
signing.sign(maven);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user