-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add support for Nexus, switch to the new CI (#158)
* refactor: add MavenCentralSnapshots back * doc: add missing documentation * refactor!: restrucure the plugin internally * build: drop unused library * style: remove blank line * refactor!: further refactoring + doc * fix: pass down the password appropriately * doc: update the README.md file * build: use the latest version of itself * ci: try to switch to semantic release * ci: update build-check-deploy-gradle-action * ci: use a custom checkout
- Loading branch information
Showing
12 changed files
with
357 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,61 +20,22 @@ jobs: | |
matrix: | ||
os: [windows, macos, ubuntu] | ||
runs-on: ${{ matrix.os }}-latest | ||
env: | ||
TERM: dumb | ||
steps: | ||
# Checkout the repository | ||
- name: Checkout | ||
uses: danysk/[email protected] | ||
- name: Configure the Windows Pagefile | ||
if: ${{ runner.os == 'Windows' }} | ||
uses: al-cheb/[email protected] | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v2 | ||
uses: DanySK/[email protected] | ||
- uses: DanySK/[email protected] | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
~/.gradle/jdks | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Build | ||
shell: bash | ||
run: ./gradlew assemble | ||
- name: Check | ||
shell: bash | ||
run: ./gradlew check --parallel | ||
- name: CodeCov | ||
if: ${{ runner.os == 'Linux' }} | ||
uses: codecov/codecov-action@v2 | ||
- name: Deploy | ||
if: ${{ runner.os == 'Linux' && github.event_name == 'push' }} | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} | ||
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} | ||
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | ||
MAVEN_CENTRAL_USERNAME: danysk | ||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} | ||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} | ||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | ||
run: | | ||
./gradlew publishPluginMavenPublicationToMavenCentralRepository publishKotlinMavenPublicationToMavenCentralRepository | ||
./gradlew publishPluginMavenPublicationToGithubRepository || true | ||
./gradlew publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET || true | ||
- name: Turn off the Gradle Daemon | ||
shell: bash | ||
run: ./gradlew --stop | ||
- name: Cleanup the Gradle cache | ||
if: ${{ runner.os != 'Windows' }} | ||
shell: bash | ||
run: | | ||
rm -f ~/.gradle/caches/modules-2/modules-2.lock | ||
rm -f ~/.gradle/caches/modules-2/gc.properties | ||
- name: Force the Gradle cleanup on Windows | ||
if: ${{ runner.os == 'Windows' }} | ||
run: | | ||
Remove-Item -Force c:\Users\runneradmin\.gradle\caches\modules-2\modules-2.lock | ||
Remove-Item -Force c:\Users\runneradmin\.gradle\caches\modules-2\gc.properties | ||
deploy-command: | | ||
npm install | ||
npx semantic-release | ||
gradle-termination-command: ./gradlew --stop | ||
java-distribution: temurin | ||
java-version: '17' | ||
should-run-codecov: ${{ runner.os == 'Linux' }} | ||
should-deploy: ${{ runner.os == 'Linux' && github.event_name == 'push' }} | ||
github-token: ${{ github.token }} | ||
gradle-publish-secret: ${{ secrets.GRADLE_PUBLISH_SECRET }} | ||
gradle-publish-key: ${{ secrets.GRADLE_PUBLISH_KEY }} | ||
maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | ||
signing-key: ${{ secrets.SIGNING_KEY }} | ||
signing-password: ${{ secrets.SIGNING_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tagFormat: "${version}" | ||
plugins: | ||
- "@semantic-release/commit-analyzer" | ||
- "@semantic-release/release-notes-generator" | ||
- "@semantic-release/changelog" | ||
- | ||
- "@semantic-release/exec" | ||
- publishCmd: | | ||
./gradlew releaseKotlin | ||
./gradlew publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET | ||
./gradlew publishPluginMavenPublicationToGithubRepository || true | ||
- "@semantic-release/github" | ||
- "@semantic-release/git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,136 @@ | ||
# publish-on-central | ||
A Gradle plugin for streamlined publishing on Maven Central | ||
(and other Maven / Nexus repositories). | ||
This plugin is meant to provide an even easier configuration than | ||
[`io.github.gradle-nexus:publish-plugin`](https://github.com/gradle-nexus/publish-plugin) | ||
(from which this plugin depends), | ||
with the goal of supporting highly automated workflows with minimal configuration. | ||
|
||
## Rationale | ||
Publishing on Maven Central requires too much configuration? | ||
Well, I agree. | ||
This plugin is here to simplify your life by automatically configuring (when applied) the Java plugin and the Publish | ||
Plugin to create source and javadoc jars, sign them for you and send them to OSSRH's Sonatype Nexus. | ||
This plugin is here to simplify your life by automatically | ||
scanning all the software components produced by any plugin, | ||
configuring a corresponding publication, | ||
filling all the information required by OSSRH, | ||
configuring tasks for generating javadoc and source jar files, | ||
activating the signing plugin, | ||
and preparing tasks to upload, close, and release the artifact. | ||
|
||
## Usage | ||
This plugin supports both targets that use Sonatype Nexus (such as Maven Central) | ||
and targets that do not, such as GitHub Packages. | ||
|
||
### Provided tasks | ||
|
||
* `sourcesJar`: a `Jar` task preconfigured to collect and pack `allSource` from the `main` source set | ||
* `javadocJar`: a `Jar` task preconfigured to | ||
1. Detect if a javadoc tasks exists, and in case depend on it, and pack its output folder | ||
2. Detect if a dokkaJavadoc tasks exists, and to the same as above | ||
* One task for each combination of `SoftwareComponent` and repositories. | ||
The `MavenCentral` and `MavenCentralSnapshots` are predefined, other repositories can be added. | ||
* One task for each combination of `SoftwareComponent` and repository, | ||
unless manually deactivated, a `MavenCentral` repository is created by default. | ||
* One task for publishing `All` software components to any target repository | ||
* For every repository with an associated Sonatype Nexus instance, additional tasks are generated to control the | ||
upload into a new staging repository, its closure, and its release. | ||
|
||
In short, if you have (for instance) a mixed Java-Kotlin project, | ||
you should find the following tasks: | ||
|
||
* `closeJavaMavenOnMavenCentralNexus` | ||
* `closeKotlinMavenOnMavenCentralNexus` | ||
* `publishJavaMavenPublicationToMavenCentralRepository` | ||
* `publishKotlinMavenPublicationToMavenCentralRepository` | ||
* `publishAllPublicationsToMavenCentralRepository` | ||
* `publishJavaMavenPublicationToMavenLocalRepository` | ||
* `publishKotlinMavenPublicationToMavenLocalRepository` | ||
* `publishAllPublicationsToMavenLocalRepository` | ||
* `releaseJavaMavenOnMavenCentralNexus` | ||
* `releaseKotlinMavenOnMavenCentralNexus` | ||
* `uploadJavaMavenToMavenCentralNexus` | ||
* `uploadKotlinMavenToMavenCentralNexus` | ||
|
||
If you add a custom repository, say `myRepo`, you would also find the following tasks: | ||
|
||
* `publishJavaMavenPublicationToMyRepoRepository` | ||
* `publishKotlinMavenPublicationToMyRepoRepository` | ||
* `publishAllPublicationsToMyRepoRepository` | ||
|
||
and if `myRepo` has configured an URL for an associated Nexus instance, the following ones: | ||
|
||
* `publishJavaMavenPublicationToMyRepoRepository` | ||
* `publishKotlinMavenPublicationToMyRepoRepository` | ||
* `publishAllPublicationsToMyRepoRepository` | ||
|
||
|
||
which is what needs to get called to have your artifacts uploaded on OSSRH Nexus instance. | ||
|
||
### Importing the plugin | ||
|
||
```kotlin | ||
plugins { | ||
id ("org.danilopianini.publish-on-central") version "0.5.1" | ||
id ("org.danilopianini.publish-on-central") version "<pick the latest>") | ||
} | ||
``` | ||
The plugin is configured to react to the application of the `java` plugin, and to apply the `maven-publish` and `signing` plugin if they are not applied. | ||
|
||
### Configuring the plugin | ||
|
||
```kotlin | ||
// The package name is equal to the project name | ||
group = "your.group.id" // This must be configured for the generated pom.xml to work correctly | ||
/* | ||
* The plugin comes with defaults that are useful to myself. You should configure it to behave as you please: | ||
*/ | ||
publishOnCentral { | ||
// Set to false if you do not want the MavenCentral repository to be automatically configured | ||
configureMavenCentral.set(true) | ||
// The following values are the default, if they are ok with you, just omit them | ||
projectDescription = "No description provided" | ||
projectLongName = project.name | ||
licenseName = "Apache License, Version 2.0" | ||
licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0" | ||
projectUrl = "https://github.com/DanySK/${project.name}" | ||
scmConnection = "git:[email protected]:DanySK/${project.name}" | ||
projectDescription.set("No description provided") | ||
projectLongName.set(project.name) | ||
licenseName.set("Apache License, Version 2.0") | ||
licenseUrl.set("http://www.apache.org/licenses/LICENSE-2.0") | ||
projectUrl.set("https://github.com/DanySK/${project.name}") | ||
scmConnection.set("git:[email protected]:DanySK/${project.name}") | ||
/* | ||
* The plugin is pre-configured to fetch credentials for Maven Central from the environment | ||
* Username from: MAVEN_CENTRAL_USERNAME | ||
* Password from: MAVEN_CENTRAL_PASSWORD | ||
* | ||
* In case of failure, it falls back to properties mavenCentralUsername and mavenCentralPassword respectively | ||
* The plugin is pre-configured to fetch credentials for Maven Central from the context in the following order: | ||
* 1. Environment variables MAVEN_CENTRAL_USERNAME and MAVEN_CENTRAL_PASSWORD | ||
* 2. Project properties mavenCentralUsername and mavenCentralPassword | ||
* 3. Project properties sonatypeUsername and sonatypePassword | ||
* 4. Project properties ossrhUsername and ossrhPassword | ||
* | ||
* They can be further customized through values or providers: | ||
*/ | ||
mavenCentral.user.set("...") | ||
mavenCentral.password.set(provider { "..." }) | ||
|
||
/* | ||
* This publication can be sent to other destinations, e.g. GitHub | ||
* The publications can be sent to other destinations, e.g. GitHub | ||
* The task name would be 'publishAllPublicationsToGitHubRepository' | ||
*/ | ||
repository("https://maven.pkg.github.com/OWNER/REPOSITORY", "GitHub") { | ||
user = System.getenv("GITHUB_USERNAME") | ||
password = System.getenv("GITHUB_TOKEN") | ||
user.set(System.getenv("GITHUB_USERNAME")) | ||
password.set(System.getenv("GITHUB_TOKEN")) | ||
} | ||
|
||
/* | ||
* Here is an example of a repository with a custom Nexus instance | ||
*/ | ||
repository("https://some/valid/repo/with/nexus", "MyNexus") { | ||
user.set(mavenCentral.user) // mavenCentral is accessible for | ||
password.set(System.getenv("GITHUB_TOKEN")) | ||
nexusUrl = "https://some/valid/nexus/instance" | ||
// nexusTimeOut and nexusConnectionTimeOut can be configured, too. | ||
} | ||
/* | ||
* A simplified handler is available for publishing on the Snapshots repository of Maven Central | ||
*/ | ||
if (project.version.endsWith("-SNAPSHOT")) { // Avoid stable versions being pushed there... | ||
mavenCentralSnapshotRepository() // Imports user and password from the configuration for Maven Central | ||
// mavenCentralSnapshotRepository() { | ||
mavenCentralSnapshotsRepository() // Imports user and password from the configuration for Maven Central | ||
// mavenCentralSnapshotsRepository() { | ||
// ...but they can be customized as per any other repository | ||
// } | ||
} | ||
/* | ||
* You may also want to configure publications created by other plugins | ||
* like the one that goes on Central. Typically, for instance, for publishing | ||
* Gradle plugins to Maven Central. | ||
* It can be done as follows. | ||
*/ | ||
publishing { | ||
publications { | ||
withType<MavenPublication> { | ||
configurePomForMavenCentral() | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Developers and contributors must be added manually | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,18 +93,17 @@ gradlePlugin { | |
} | ||
|
||
publishOnCentral { | ||
projectDescription = projectDetails | ||
projectLongName = fullName | ||
projectUrl = websiteUrl | ||
scmConnection = "git:[email protected]:DanySK/$name" | ||
projectDescription.set(projectDetails) | ||
projectLongName.set(fullName) | ||
projectUrl.set(websiteUrl) | ||
scmConnection.set("git:[email protected]:DanySK/$name") | ||
repository("https://maven.pkg.github.com/DanySK/$name".toLowerCase()) { | ||
user = "danysk" | ||
password = System.getenv("GITHUB_TOKEN") | ||
user.set("danysk") | ||
password.set("GITHUB_TOKEN") | ||
} | ||
publishing { | ||
publications { | ||
withType<MavenPublication> { | ||
configurePomForMavenCentral() | ||
pom { | ||
developers { | ||
developer { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"devDependencies": { | ||
"@semantic-release/changelog": "6.0.1", | ||
"@semantic-release/exec": "6.0.2", | ||
"@semantic-release/git": "10.0.1" | ||
}, | ||
"engines": { | ||
"node": "16.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.