Skip to content

Commit 145ded6

Browse files
committed
Support Deploying to Central Portal
Closes gh-70
1 parent f7255c0 commit 145ded6

File tree

8 files changed

+39
-215
lines changed

8 files changed

+39
-215
lines changed

.github/workflows/deploy-artifacts.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55
inputs:
66
should-deploy-artifacts:
7-
description: Whether artifacts should be deployed.
7+
description: Whether artifacts should be deployed (true|false|central|artifactory).
88
required: true
99
type: string
1010
outputs:
@@ -21,9 +21,9 @@ on:
2121
required: false
2222
ARTIFACTORY_PASSWORD:
2323
required: false
24-
OSSRH_S01_TOKEN_USERNAME:
24+
CENTRAL_TOKEN_USERNAME:
2525
required: false
26-
OSSRH_S01_TOKEN_PASSWORD:
26+
CENTRAL_TOKEN_PASSWORD:
2727
required: false
2828
GPG_PRIVATE_KEY:
2929
required: false
@@ -40,7 +40,7 @@ env:
4040
jobs:
4141
deploy-artifacts:
4242
name: Deploy Artifacts
43-
if: ${{ inputs.should-deploy-artifacts == 'true' }}
43+
if: ${{ inputs.should-deploy-artifacts != 'false' }}
4444
runs-on: ubuntu-latest
4545
outputs:
4646
artifacts-deployed: ${{ steps.artifacts-deployed.outputs.result }}
@@ -63,7 +63,25 @@ jobs:
6363
branch="${VERSION%.*}.x"
6464
fi
6565
echo "branch=$branch" >> $GITHUB_OUTPUT
66-
- name: Deploy Artifacts
66+
- id: deploy-location
67+
name: Default the Deploy Location
68+
env:
69+
SHOULD_DEPLOY_ARTIFACTS: ${{ inputs.should-deploy-artifacts }}
70+
VERSION: ${{ steps.project-version.outputs.version }}
71+
run: |
72+
deploy_location="$SHOULD_DEPLOY_ARTIFACTS"
73+
if [[ "$deploy_location" = "true" ]] ; then
74+
if [[ "$VERSION" =~ "-" ]] ; then
75+
# -SNAPSHOT, -M\d+, and -RC\d+ all go to artifactory by default to remain passive
76+
# Newer generations will only deploy -SNAPSHOT to artifactory, but they must opt into central explicitly
77+
deploy_location=artifactory
78+
else
79+
deploy_location=central
80+
fi
81+
fi
82+
echo "deploy_location=$deploy_location" >> $GITHUB_OUTPUT
83+
- name: Deploy to Artifactory
84+
if: ${{ steps.deploy-location.outputs.deploy_location == 'artifactory' }}
6785
env:
6886
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
6987
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
@@ -73,7 +91,19 @@ jobs:
7391
ARTIFACTORY_USER_AGENT_NAME: GitHub Actions
7492
ARTIFACTORY_USER_AGENT_VERSION: Unknown
7593
ARTIFACTORY_VCS_REVISION: ${{ github.sha }}
76-
run: ./gradlew publishArtifacts finalizeDeployArtifacts -PossrhUsername="$OSSRH_TOKEN_USERNAME" -PossrhPassword="$OSSRH_TOKEN_PASSWORD" -PartifactoryUsername="$ARTIFACTORY_USERNAME" -PartifactoryPassword="$ARTIFACTORY_PASSWORD" --stacktrace
94+
run: ./gradlew publishArtifacts -PartifactoryUsername="$ARTIFACTORY_USERNAME" -PartifactoryPassword="$ARTIFACTORY_PASSWORD" --stacktrace
95+
- name: Stage Local Artifacts for Publishing to Central
96+
if: ${{ steps.deploy-location.outputs.deploy_location == 'central' }}
97+
env:
98+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
99+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
100+
run: ./gradlew publishAllPublicationsToLocalRepository --stacktrace
101+
- name: Publish Staged Artifacts to Central
102+
uses: spring-io/central-publish-action@0cdd90d12e6876341e82860d951e1bcddc1e51b6 # v0.2.0
103+
with:
104+
token-name: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
105+
token: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
106+
dir: build/publications/repos
77107
- id: artifacts-deployed
78108
name: Artifacts Deployed
79109
run: echo "result=true" >> $GITHUB_OUTPUT

buildSrc/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ repositories {
1616
}
1717

1818
dependencies {
19-
implementation "io.github.gradle-nexus:publish-plugin:2.0.0"
2019
implementation "io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.41"
2120
implementation "io.spring.nohttp:nohttp-gradle:0.0.11"
2221
implementation "org.jfrog.buildinfo:build-info-extractor-gradle:5.2.0"

buildSrc/src/main/java/io/spring/gradle/convention/SpringRootProjectPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.gradle.api.plugins.BasePlugin;
2222
import org.gradle.api.plugins.PluginManager;
2323

24-
import org.springframework.gradle.maven.SpringNexusPlugin;
2524
import org.springframework.gradle.nohttp.SpringNoHttpPlugin;
2625

2726
/**
@@ -34,7 +33,6 @@ public void apply(Project project) {
3433
PluginManager pluginManager = project.getPluginManager();
3534
pluginManager.apply(BasePlugin.class);
3635
pluginManager.apply(SpringNoHttpPlugin.class);
37-
pluginManager.apply(SpringNexusPlugin.class);
3836

3937
// Apply default repositories
4038
project.getRepositories().mavenCentral();

buildSrc/src/main/java/org/springframework/gradle/maven/SpringNexusPlugin.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

maven-plugin/README.adoc

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ plugins {
1212
----
1313

1414
== Overview
15-
1615
This plugin has two main goals:
1716

1817
1. Automatically apply plugins and configuration for publishing artifacts to both Maven Central (Sonatype) and Spring (Artifactory).
1918
2. Provide tasks for automatically choosing which artifact repository to publish artifacts to based on the project version.
2019

21-
This plugin performs the following on the root project:
22-
23-
* Applies the `io.github.gradle-nexus.publish-plugin` plugin
24-
* Creates an `ossrh` repository for publishing artifacts to the Sonatype staging repository
25-
* Configures the `publishArtifacts` task to publish releases to the Sonatype staging repository (`ossrh`)
26-
* Configures the `finalizeDeployArtifacts` task to close and release any opened staging repository (for Sonatype releases only)
27-
28-
This plugin also performs the following on each sub-module it is applied to:
20+
This plugin performs the following on each sub-module it is applied to:
2921

3022
* Applies the `maven-publish` plugin
3123
* Applies the `signing` plugin
@@ -35,59 +27,9 @@ This plugin also performs the following on each sub-module it is applied to:
3527
* Configures the `publishing` extension to sign artifacts
3628
* Creates a `local` repository for publishing artifacts to a local directory
3729
* Configures the `artifactory` extension using gradle properties
38-
* Configures the `publishArtifacts` task to publish snapshots, milestones and release candidates to Artifactory
3930

4031
== Task Reference
4132

42-
=== `publishArtifacts`
43-
44-
This task works together with `finalizeDeployArtifacts` to publish artifacts to the appropriate artifact repository and automatically close and release staging repositories (for Sonatype releases only) once publishing is complete.
45-
46-
For snapshots, milestones , and release candidates (e.g. `-SNAPSHOT`, `-M1`, `-RC1`, etc.), Artifactory is used.
47-
For releases (any other version), the Sonatype staging repository is used instead.
48-
49-
The default Nexus URL is `https://s01.oss.sonatype.org/service/local/`, which is for the Sonatype staging repository.
50-
You can override this by passing the optional environment variable `OSSRH_URL`.
51-
52-
The default Nexus snapshots URL is `https://s01.oss.sonatype.org/content/repositories/snapshots/`.
53-
You can override this by passing the optional environment variable `OSSRH_SNAPSHOT_REPOSITORY_URL`.
54-
55-
The default Artifactory URL is `https://repo.spring.io`.
56-
You can override this by passing the optional environment variable `ARTIFACTORY_URL`.
57-
58-
*Example:*
59-
60-
[source,bash]
61-
----
62-
export ORG_GRADLE_PROJECT_signingKey=...
63-
export ORG_GRADLE_PROJECT_signingPassword=...
64-
OSSRH_USERNAME=...
65-
OSSRH_PASSWORD=...
66-
ARTIFACTORY_USERNAME=...
67-
ARTIFACTORY_PASSWORD=...
68-
./gradlew publishArtifacts finalizeDeployArtifacts -PossrhUsername="$OSSRH_USERNAME" -PossrhPassword="$OSSRH_PASSWORD" -PartifactoryUsername="$ARTIFACTORY_USERNAME" -PartifactoryPassword="$ARTIFACTORY_PASSWORD" --stacktrace
69-
----
70-
71-
== `publishToOssrh`
72-
73-
This task is provided by the `maven-publish` plugin when the `ossrh` repository is defined, and can be used directly to publish snapshots and other artifacts to the Sonatype staging repository.
74-
75-
[NOTE]
76-
====
77-
You will need to call `closeAndReleaseOssrhStagingRepository` yourself.
78-
====
79-
80-
*Example:*
81-
82-
[source,bash]
83-
----
84-
export ORG_GRADLE_PROJECT_signingKey=...
85-
export ORG_GRADLE_PROJECT_signingPassword=...
86-
OSSRH_USERNAME=...
87-
OSSRH_PASSWORD=...
88-
./gradlew publishToOssrh closeAndReleaseOssrhStagingRepository -PossrhUsername="$OSSRH_USERNAME" -PossrhPassword="$OSSRH_PASSWORD" --stacktrace
89-
----
90-
9133
== `artifactoryPublish`
9234

9335
This task is provided by the `com.jfrog.artifactory` plugin, and can be used directly to publish artifacts (including releases) to Artifactory.

maven-plugin/spring-security-maven-plugin.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ repositories {
3131

3232
dependencies {
3333
management platform(project(":dependencies"))
34-
implementation "io.github.gradle-nexus:publish-plugin:2.0.0"
3534
implementation "org.jfrog.buildinfo:build-info-extractor-gradle:5.2.0"
3635

3736
testImplementation "org.junit.jupiter:junit-jupiter"

maven-plugin/src/main/java/io/spring/gradle/plugin/maven/SpringMavenPlugin.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,9 @@ public class SpringMavenPlugin implements Plugin<Project> {
2727

2828
@Override
2929
public void apply(Project project) {
30-
// Create publish task
31-
project.getTasks().register("publishArtifacts", (task) -> {
32-
task.setGroup("Publishing");
33-
task.setDescription("Publish the artifacts to either Artifactory or Maven Central based on the version");
34-
});
35-
36-
// Create finalize task to run after publish task
37-
project.getTasks().register("finalizeDeployArtifacts", (task) -> {
38-
task.setGroup("Publishing");
39-
task.setDescription(
40-
"Automatically close and release staging repositories when required based on the version");
41-
});
42-
4330
PluginManager pluginManager = project.getPluginManager();
44-
if (project.getRootProject().equals(project)) {
45-
pluginManager.apply(SpringNexusPlugin.class);
46-
}
47-
else {
48-
pluginManager.apply(SpringMavenPublishPlugin.class);
49-
pluginManager.apply(SpringArtifactoryPlugin.class);
50-
}
31+
pluginManager.apply(SpringMavenPublishPlugin.class);
32+
pluginManager.apply(SpringArtifactoryPlugin.class);
5133
}
5234

5335
}

maven-plugin/src/main/java/io/spring/gradle/plugin/maven/SpringNexusPlugin.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)