buildSrc to publish
This commit is contained in:
parent
53fec9e98b
commit
304636520d
|
@ -2,10 +2,3 @@ apply plugin: 'io.spring.convention.bom'
|
|||
|
||||
sonarqube.skipProject = true
|
||||
|
||||
project.rootProject.allprojects.each { p ->
|
||||
p.plugins.withType(io.spring.gradle.convention.SpringMavenPlugin) {
|
||||
if (!project.name.equals(p.name)) {
|
||||
project.mavenBom.projects.add(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,11 +71,11 @@ dependencies {
|
|||
implementation 'net.sourceforge.saxon:saxon:9.1.0.8'
|
||||
implementation localGroovy()
|
||||
|
||||
implementation 'io.github.gradle-nexus:publish-plugin:1.1.0'
|
||||
implementation 'io.projectreactor:reactor-core:3.4.6'
|
||||
implementation 'gradle.plugin.org.gretty:gretty:3.0.1'
|
||||
implementation 'com.apollographql.apollo:apollo-runtime:2.4.5'
|
||||
implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
|
||||
implementation 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.1'
|
||||
implementation 'io.spring.gradle:docbook-reference-plugin:0.3.1'
|
||||
implementation 'io.spring.gradle:propdeps-plugin:0.0.10.RELEASE'
|
||||
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.15'
|
||||
|
|
|
@ -2,10 +2,8 @@ package io.spring.gradle.convention
|
|||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.plugins.MavenPlugin
|
||||
import org.gradle.plugins.signing.SigningPlugin
|
||||
import org.sonarqube.gradle.SonarQubePlugin
|
||||
import org.springframework.gradle.maven.SpringMavenPlugin
|
||||
|
||||
public class MavenBomPlugin implements Plugin<Project> {
|
||||
static String MAVEN_BOM_TASK_NAME = "mavenBom"
|
||||
|
@ -14,15 +12,10 @@ public class MavenBomPlugin implements Plugin<Project> {
|
|||
project.configurations {
|
||||
archives
|
||||
}
|
||||
project.plugins.apply('io.spring.convention.artifactory')
|
||||
project.plugins.apply('io.spring.convention.maven')
|
||||
project.plugins.apply(MavenPlugin)
|
||||
project.plugins.apply(SigningPlugin)
|
||||
project.plugins.apply("io.spring.convention.ossrh")
|
||||
project.plugins.apply(SpringMavenPlugin)
|
||||
|
||||
project.group = project.rootProject.group
|
||||
project.task(MAVEN_BOM_TASK_NAME, type: MavenBomTask, group: 'Generate', description: 'Configures the pom as a Maven Build of Materials (BOM)')
|
||||
project.install.dependsOn project.mavenBom
|
||||
project.tasks.uploadArchives.dependsOn project.mavenBom
|
||||
project.tasks.artifactoryPublish.dependsOn project.mavenBom
|
||||
|
||||
|
@ -31,7 +24,7 @@ public class MavenBomPlugin implements Plugin<Project> {
|
|||
}
|
||||
|
||||
project.rootProject.allprojects.each { p ->
|
||||
p.plugins.withType(io.spring.gradle.convention.SpringMavenPlugin) {
|
||||
p.plugins.withType(SpringMavenPlugin) {
|
||||
if (!project.name.equals(p.name)) {
|
||||
project.mavenBom.projects.add(p)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.gradle.api.Plugin
|
|||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.api.plugins.PluginManager
|
||||
import org.springframework.gradle.maven.SpringNexusPublishPlugin
|
||||
|
||||
class RootProjectPlugin implements Plugin<Project> {
|
||||
|
||||
|
@ -30,6 +31,7 @@ class RootProjectPlugin implements Plugin<Project> {
|
|||
pluginManager.apply(BasePlugin)
|
||||
pluginManager.apply(SchemaPlugin)
|
||||
pluginManager.apply(NoHttpPlugin)
|
||||
pluginManager.apply(SpringNexusPublishPlugin)
|
||||
pluginManager.apply("org.sonarqube")
|
||||
|
||||
project.repositories.mavenCentral()
|
||||
|
@ -50,17 +52,7 @@ class RootProjectPlugin implements Plugin<Project> {
|
|||
|
||||
def finalizeDeployArtifacts = project.task("finalizeDeployArtifacts")
|
||||
if (Utils.isRelease(project) && project.hasProperty("ossrhUsername")) {
|
||||
project.ext.nexusUsername = project.ossrhUsername
|
||||
project.ext.nexusPassword = project.ossrhPassword
|
||||
project.getPluginManager().apply("io.codearte.nexus-staging")
|
||||
finalizeDeployArtifacts.dependsOn project.tasks.closeAndReleaseRepository
|
||||
project.nexusStaging {
|
||||
packageGroup = 'org.springframework'
|
||||
|
||||
// try for 5 minutes total
|
||||
numberOfRetries = 60 // default is 20
|
||||
delayBetweenRetriesInMillis = 5000 // default is 2000
|
||||
}
|
||||
finalizeDeployArtifacts.dependsOn project.tasks.closeAndReleaseOssrhtagingRepository
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,212 +0,0 @@
|
|||
package io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.XmlProvider
|
||||
import org.gradle.api.artifacts.component.ModuleComponentSelector
|
||||
import org.gradle.api.artifacts.maven.MavenDeployment
|
||||
import org.gradle.api.artifacts.maven.MavenPom
|
||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||
import org.gradle.api.plugins.JavaBasePlugin
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.plugins.JavaPluginConvention
|
||||
import org.gradle.api.plugins.MavenPlugin
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
import org.gradle.plugins.signing.SigningPlugin
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
public class SpringMavenPlugin implements Plugin<Project> {
|
||||
private static final String ARCHIVES = "archives";
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPluginManager().apply(JavaPlugin.class);
|
||||
project.getPluginManager().apply(MavenPlugin.class);
|
||||
project.getPluginManager().apply(SigningPlugin.class);
|
||||
|
||||
Javadoc javadoc = (Javadoc) project.getTasks().findByPath("javadoc");
|
||||
Jar javadocJar = project.getTasks().create("javadocJar", Jar.class);
|
||||
javadocJar.setClassifier("javadoc");
|
||||
javadocJar.from(javadoc);
|
||||
|
||||
JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
SourceSet mainSourceSet = java.getSourceSets().getByName("main");
|
||||
Jar sourcesJar = project.getTasks().create("sourcesJar", Jar.class);
|
||||
sourcesJar.setClassifier("sources");
|
||||
sourcesJar.from(mainSourceSet.getAllSource());
|
||||
|
||||
project.getArtifacts().add(ARCHIVES, javadocJar);
|
||||
project.getArtifacts().add(ARCHIVES, sourcesJar);
|
||||
|
||||
project.install {
|
||||
repositories.mavenInstaller {
|
||||
configurePom(project, pom)
|
||||
}
|
||||
}
|
||||
project.uploadArchives {
|
||||
repositories.mavenDeployer {
|
||||
configurePom(project, pom)
|
||||
}
|
||||
}
|
||||
|
||||
inlineDependencyManagement(project);
|
||||
|
||||
def hasSigningKey = project.hasProperty("signing.keyId") || project.findProperty("signingKey")
|
||||
if(hasSigningKey && Utils.isRelease(project)) {
|
||||
sign(project)
|
||||
}
|
||||
|
||||
project.getPluginManager().apply("io.spring.convention.ossrh");
|
||||
}
|
||||
|
||||
private void inlineDependencyManagement(Project project) {
|
||||
project.install {
|
||||
repositories.mavenInstaller {
|
||||
configurePomForInlineDependencies(project, pom)
|
||||
}
|
||||
}
|
||||
project.uploadArchives {
|
||||
repositories.mavenDeployer {
|
||||
configurePomForInlineDependencies(project, pom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configurePomForInlineDependencies(Project project, MavenPom pom) {
|
||||
pom.withXml { XmlProvider xml ->
|
||||
project.plugins.withType(JavaBasePlugin) {
|
||||
def dependencies = xml.asNode()?.dependencies?.dependency
|
||||
def configuredDependencies = project.configurations.findAll{ it.canBeResolved && it.canBeConsumed }*.incoming*.resolutionResult*.allDependencies.flatten()
|
||||
dependencies?.each { Node dep ->
|
||||
def group = dep.groupId.text()
|
||||
def name = dep.artifactId.text()
|
||||
|
||||
ResolvedDependencyResult resolved = configuredDependencies.find { r ->
|
||||
(r.requested instanceof ModuleComponentSelector) &&
|
||||
(r.requested.group == group) &&
|
||||
(r.requested.module == name)
|
||||
}
|
||||
|
||||
if (!resolved) {
|
||||
return
|
||||
}
|
||||
|
||||
def versionNode = dep.version
|
||||
if (!versionNode) {
|
||||
dep.appendNode('version')
|
||||
}
|
||||
def moduleVersion = resolved.selected.moduleVersion
|
||||
dep.groupId[0].value = moduleVersion.group
|
||||
dep.artifactId[0].value = moduleVersion.name
|
||||
dep.version[0].value = moduleVersion.version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sign(Project project) {
|
||||
project.install {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> project.signing.signPom(deployment) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> project.signing.signPom(deployment) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.signing {
|
||||
required { project.gradle.taskGraph.hasTask("uploadArchives") }
|
||||
def signingKeyId = project.findProperty("signingKeyId")
|
||||
def signingKey = project.findProperty("signingKey")
|
||||
def signingPassword = project.findProperty("signingPassword")
|
||||
if (signingKeyId) {
|
||||
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
|
||||
} else if (signingKey) {
|
||||
useInMemoryPgpKeys(signingKey, signingPassword)
|
||||
}
|
||||
sign project.configurations.archives
|
||||
}
|
||||
}
|
||||
|
||||
private static void configurePom(Project project, MavenPom pom) {
|
||||
pom.whenConfigured { p ->
|
||||
p.dependencies = p.dependencies.sort { dep ->
|
||||
"$dep.scope:$dep.optional:$dep.groupId:$dep.artifactId"
|
||||
}
|
||||
}
|
||||
|
||||
pom.project {
|
||||
boolean isWar = project.hasProperty("war");
|
||||
String projectVersion = String.valueOf(project.getVersion());
|
||||
String projectName = Utils.getProjectName(project);
|
||||
|
||||
if(isWar) {
|
||||
packaging = "war"
|
||||
}
|
||||
name = project.name
|
||||
description = project.name
|
||||
url = 'https://spring.io/spring-security'
|
||||
organization {
|
||||
name = 'spring.io'
|
||||
url = 'https://spring.io/'
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache Software License, Version 2.0'
|
||||
url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
distribution 'repo'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/spring-projects/spring-security'
|
||||
connection = 'scm:git:git://github.com/spring-projects/spring-security'
|
||||
developerConnection = 'scm:git:git://github.com/spring-projects/spring-security'
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'rwinch'
|
||||
name = 'Rob Winch'
|
||||
email = 'rwinch@pivotal.io'
|
||||
}
|
||||
developer {
|
||||
id = 'jgrandja'
|
||||
name = 'Joe Grandja'
|
||||
email = 'jgrandja@pivotal.io'
|
||||
}
|
||||
}
|
||||
|
||||
if(isWar) {
|
||||
properties {
|
||||
'm2eclipse.wtp.contextRoot' '/'
|
||||
}
|
||||
}
|
||||
if (Utils.isSnapshot(project)) {
|
||||
repositories {
|
||||
repository {
|
||||
id 'spring-snapshot'
|
||||
url 'https://repo.spring.io/snapshot'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Utils.isMilestone(project)) {
|
||||
repositories {
|
||||
repository {
|
||||
id 'spring-milestone'
|
||||
url 'https://repo.spring.io/milestone'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,8 @@ package io.spring.gradle.convention;
|
|||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaLibraryPlugin;
|
||||
import org.gradle.api.plugins.MavenPlugin;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.plugins.PluginManager
|
||||
import org.springframework.gradle.maven.SpringMavenPlugin;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
|
@ -30,9 +31,7 @@ class SpringModulePlugin extends AbstractSpringJavaPlugin {
|
|||
void additionalPlugins(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(JavaLibraryPlugin.class)
|
||||
pluginManager.apply(MavenPlugin.class);
|
||||
pluginManager.apply("io.spring.convention.maven");
|
||||
pluginManager.apply("io.spring.convention.artifactory");
|
||||
pluginManager.apply(SpringMavenPlugin.class);
|
||||
pluginManager.apply("io.spring.convention.jacoco");
|
||||
|
||||
def deployArtifacts = project.task("deployArtifacts")
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.MavenPom;
|
||||
import org.gradle.api.publish.maven.MavenPomDeveloperSpec;
|
||||
import org.gradle.api.publish.maven.MavenPomIssueManagement;
|
||||
import org.gradle.api.publish.maven.MavenPomLicenseSpec;
|
||||
import org.gradle.api.publish.maven.MavenPomOrganization;
|
||||
import org.gradle.api.publish.maven.MavenPomScm;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
public class MavenPublishingConventionsPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().withType(MavenPublication.class)
|
||||
.all((mavenPublication) -> customizePom(mavenPublication.getPom(), project));
|
||||
customizeJavaPlugin(project);
|
||||
});
|
||||
}
|
||||
|
||||
private void customizePom(MavenPom pom, Project project) {
|
||||
pom.getUrl().set("https://spring.io/projects/spring-security");
|
||||
pom.getName().set(project.provider(project::getName));
|
||||
pom.getDescription().set(project.provider(project::getDescription));
|
||||
pom.organization(this::customizeOrganization);
|
||||
pom.licenses(this::customizeLicences);
|
||||
pom.developers(this::customizeDevelopers);
|
||||
pom.scm((scm) -> customizeScm(scm));
|
||||
pom.issueManagement(this::customizeIssueManagement);
|
||||
}
|
||||
|
||||
private void customizeOrganization(MavenPomOrganization organization) {
|
||||
organization.getName().set("Pivotal Software, Inc.");
|
||||
organization.getUrl().set("https://spring.io");
|
||||
}
|
||||
|
||||
private void customizeLicences(MavenPomLicenseSpec licences) {
|
||||
licences.license((licence) -> {
|
||||
licence.getName().set("Apache License, Version 2.0");
|
||||
licence.getUrl().set("https://www.apache.org/licenses/LICENSE-2.0");
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeDevelopers(MavenPomDeveloperSpec developers) {
|
||||
developers.developer((developer) -> {
|
||||
developer.getName().set("Pivotal");
|
||||
developer.getEmail().set("info@pivotal.io");
|
||||
developer.getOrganization().set("Pivotal Software, Inc.");
|
||||
developer.getOrganizationUrl().set("https://www.spring.io");
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeScm(MavenPomScm scm) {
|
||||
scm.getConnection().set("scm:git:git://github.com/spring-projects/spring-security.git");
|
||||
scm.getDeveloperConnection().set("scm:git:ssh://git@github.com/spring-projects/spring-security.git");
|
||||
scm.getUrl().set("https://github.com/spring-projects/spring-security");
|
||||
}
|
||||
|
||||
private void customizeIssueManagement(MavenPomIssueManagement issueManagement) {
|
||||
issueManagement.getSystem().set("GitHub");
|
||||
issueManagement.getUrl().set("https://github.com/spring-projects/spring-security/issues");
|
||||
}
|
||||
|
||||
private void customizeJavaPlugin(Project project) {
|
||||
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
|
||||
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
extension.withJavadocJar();
|
||||
extension.withSourcesJar();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlatformPlugin;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
public class PublishAllJavaComponentsPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().create("maven", MavenPublication.class, new Action<MavenPublication>() {
|
||||
@Override
|
||||
public void execute(MavenPublication maven) {
|
||||
project.getPlugins().withType(JavaPlatformPlugin.class)
|
||||
.all((javaPlugin) -> project.getComponents()
|
||||
.matching((component) -> component.getName().equals("javaPlatform"))
|
||||
.all((javaComponent) -> maven.from(javaComponent)));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
import io.spring.gradle.convention.Utils;
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PublishLocalPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all(new Action<MavenPublishPlugin>() {
|
||||
@Override
|
||||
public void execute(MavenPublishPlugin mavenPublish) {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getRepositories().maven(new Action<MavenArtifactRepository>() {
|
||||
@Override
|
||||
public void execute(MavenArtifactRepository maven) {
|
||||
maven.setName("local");
|
||||
maven.setUrl(new File(project.getRootDir(), "publications/repos"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
import io.spring.gradle.convention.ArtifactoryPlugin;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
|
||||
public class SpringMavenPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(SpringSigningPlugin.class);
|
||||
pluginManager.apply(SpringMavenPlugin.class);
|
||||
pluginManager.apply(MavenPublishingConventionsPlugin.class);
|
||||
pluginManager.apply(PublishAllJavaComponentsPlugin.class);
|
||||
pluginManager.apply(PublishLocalPlugin.class);
|
||||
pluginManager.apply(PublishArtifactsPlugin.class);
|
||||
pluginManager.apply(ArtifactoryPlugin.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.springframework.gradle.maven;
|
||||
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishExtension;
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
|
||||
import io.github.gradlenexus.publishplugin.NexusRepository;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
|
||||
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,70 @@
|
|||
/*
|
||||
* Copyright 2016-2019 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.gradle.maven;
|
||||
|
||||
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.api.publish.plugins.PublishingPlugin;
|
||||
import org.gradle.plugins.signing.SigningExtension;
|
||||
import org.gradle.plugins.signing.SigningPlugin;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
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(PublishingPlugin.class).all(new Action<PublishingPlugin>() {
|
||||
@Override
|
||||
public void execute(PublishingPlugin publishingPlugin) {
|
||||
PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
|
||||
Publication maven = publishing.getPublications().getByName("maven");
|
||||
signing.sign(maven);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
implementation-class=io.spring.gradle.convention.SpringMavenPlugin
|
|
@ -51,7 +51,9 @@ tasks.processResources {
|
|||
|
||||
tasks.jar.from { includeProject.sourceSets.main.output }
|
||||
|
||||
tasks.sourcesJar.from {includeProject.sourceSets.main.java}
|
||||
project.tasks.matching { t -> t.name == "sourcesJar"}.configureEach {
|
||||
from {includeProject.sourceSets.main.java }
|
||||
}
|
||||
|
||||
configure(project.tasks.withType(Test)) {
|
||||
doFirst {
|
||||
|
|
Loading…
Reference in New Issue