Skip to content

Commit b3a7f7d

Browse files
committed
Added nexus publishing block
1 parent 2b0d3ca commit b3a7f7d

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

.github/actions/maven-publish/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ runs:
3535

3636
- name: Publish Java Packages to Maven
3737
shell: bash
38-
run: ./gradlew publish -PisSnapshot=false --stacktrace
38+
run: ./gradlew publishToSonatype closeSonatypeStagingRepository -PisSnapshot=false --stacktrace
3939
env:
4040
JAVA_HOME: ${{ env.JAVA_HOME }}
4141
MAVEN_USERNAME: ${{ inputs.ossr-username }}

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414
id 'java-library'
1515
id 'jacoco'
1616
id 'me.champeau.gradle.japicmp' version '0.4.1'
17+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
1718
}
1819

1920
repositories {

gradle/maven-publish.gradle

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,18 @@ artifacts {
2525
archives sourcesJar, javadocJar
2626
}
2727

28-
29-
final releaseRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
30-
final snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
31-
3228
publishing {
3329
publications {
3430
mavenJava(MavenPublication) {
31+
from components.java
32+
33+
artifact sourcesJar
34+
artifact javadocJar
3535

3636
groupId = GROUP
3737
artifactId = POM_ARTIFACT_ID
3838
version = getVersionName()
3939

40-
artifact("$buildDir/libs/${project.name}-${version}.jar")
41-
artifact sourcesJar
42-
artifact javadocJar
43-
4440
pom {
4541
name = POM_NAME
4642
packaging = POM_PACKAGING
@@ -68,28 +64,18 @@ publishing {
6864
connection = POM_SCM_CONNECTION
6965
developerConnection = POM_SCM_DEV_CONNECTION
7066
}
71-
72-
pom.withXml {
73-
def dependenciesNode = asNode().appendNode('dependencies')
74-
75-
project.configurations.implementation.allDependencies.each {
76-
def dependencyNode = dependenciesNode.appendNode('dependency')
77-
dependencyNode.appendNode('groupId', it.group)
78-
dependencyNode.appendNode('artifactId', it.name)
79-
dependencyNode.appendNode('version', it.version)
80-
}
81-
}
8267
}
8368
}
8469
}
70+
}
71+
72+
nexusPublishing {
8573
repositories {
86-
maven {
87-
name = "sonatype"
88-
url = version.endsWith('SNAPSHOT') ? snapshotRepositoryUrl : releaseRepositoryUrl
89-
credentials {
90-
username = System.getenv("MAVEN_USERNAME")
91-
password = System.getenv("MAVEN_PASSWORD")
92-
}
74+
sonatype {
75+
nexusUrl.set(uri('https://ossrh-staging-api.central.sonatype.com/service/local/'))
76+
snapshotRepositoryUrl.set(uri('https://central.sonatype.com/repository/maven-snapshots/'))
77+
username.set(System.getenv("MAVEN_USERNAME"))
78+
password.set(System.getenv("MAVEN_PASSWORD"))
9379
}
9480
}
9581
}

0 commit comments

Comments
 (0)