Support publishing to maven central repository (#3767)

#### What type of PR is this?

/kind feature
/area core

#### What this PR does / why we need it:

Use Gradle plugin `maven-publish` to publish Halo modules(`platform.application`, `platform.plugin` and `api`) to Maven central repository.

```bash
# Try to publish to Maven local repository.
./gradlew publish
# Really publish to Maven central repository.
./gradlew -Prelease publish -PossrhUsername=username -PossrhPassword=password
```

Note that currently we only support manually publishing.

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/2730

#### Does this PR introduce a user-facing change?

```release-note
None
```
This commit is contained in:
John Niang 2023-04-18 14:28:23 +08:00 committed by GitHub
parent 8d2f081067
commit ed14fcb5f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 70 deletions

View File

@ -39,47 +39,19 @@ jobs:
filters: |
console:
- 'console/**'
- name: Check code style
run: ./gradlew check -x test
- name: Setup console environment
if: steps.changes.outputs.console == 'true'
uses: halo-sigs/actions/admin-env-setup@main
- name: Check console
if: steps.changes.outputs.console == 'true'
run: make -C console lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
cache: 'gradle'
java-version: 17
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
console:
- 'console/**'
- name: Run tests
run: ./gradlew test
- name: Check halo
run: ./gradlew check
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Setup console environment
if: steps.changes.outputs.console == 'true'
uses: halo-sigs/actions/admin-env-setup@main
- name: Test console
- name: Check console
if: steps.changes.outputs.console == 'true'
run: make -C console test
run: make -C console check
docker-build-and-push:
runs-on: ubuntu-latest
needs: test
needs: check
steps:
- uses: actions/checkout@v3
- uses: halo-sigs/actions/halo-next-docker-build@main # change the version to specific ref or release tag while the action is stable.

View File

@ -1,6 +1,6 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'halo.publish'
id "io.freefair.lombok" version "8.0.0-rc2"
}
@ -68,14 +68,3 @@ java {
tasks.named('test') {
useJUnitPlatform()
}
publishing {
publications {
library(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}

3
buildSrc/build.gradle Normal file
View File

@ -0,0 +1,3 @@
plugins {
id 'groovy-gradle-plugin'
}

View File

@ -0,0 +1,56 @@
plugins {
id 'maven-publish'
}
publishing {
publications {
def pubName = "${archivesBaseName}"
pluginManager.withPlugin('java-platform') {
pubName = pubName + 'Pom'
}
pluginManager.withPlugin('java') {
pubName = pubName + 'Library'
}
"${pubName}"(MavenPublication) {
pluginManager.withPlugin('java-platform') {
from components.javaPlatform
}
pluginManager.withPlugin('java') {
from components.java
}
pom {
licenses {
license {
name = 'The GNU General Public License v3.0'
url = 'https://www.gnu.org/licenses/gpl-3.0.en.html'
}
}
developers {
developer {
id = 'johnniang'
name = 'JohnNiang'
email = 'johnniang@foxmil.com'
}
}
scm {
connection = 'scm:git:https://github.com/halo-dev/halo.git'
developerConnection = 'scm:git:ssh://git@github.com:halo-dev/halo.git'
url = 'https://github.com/halo-dev/halo'
}
}
}
}
repositories {
mavenLocal()
if (project.hasProperty("release")) {
maven {
name = 'ossrh'
def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials(PasswordCredentials)
}
}
}
}

View File

@ -16,6 +16,8 @@ lint: build-packages ## Lint console
test: build-packages ## Test console
pnpm test:unit
check: lint test ## Check console
dev: build-packages ## Run console with development environment
pnpm dev

View File

@ -3,7 +3,8 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin
plugins {
id 'org.springframework.boot' version '3.0.5' apply false
id 'java-platform'
id 'maven-publish'
id 'halo.publish'
id 'signing'
}
group = 'run.halo.tools.platform'
@ -57,15 +58,3 @@ dependencies {
}
}
publishing {
publications {
applicationPlatform(MavenPublication) {
from components.javaPlatform
}
}
repositories {
mavenLocal()
}
}

View File

@ -1,6 +1,6 @@
plugins {
id 'java-platform'
id 'maven-publish'
id 'halo.publish'
}
group = 'run.halo.tools.platform'
@ -19,14 +19,3 @@ dependencies {
// e.g.: api 'halo.run.plugin:links-api:1.1.0'
}
}
publishing {
publications {
pluginPlatform(MavenPublication) {
from components.javaPlatform
}
}
repositories {
mavenLocal()
}
}