Skip to content

Commit 5eade53

Browse files
authored
Swap to maven-publish plugin (#547)
Maven-publish is the newer publishing plugin and has the benefit of not exposing useless scopes (like test) to consumers. See #545
1 parent 1e483db commit 5eade53

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

.github/workflows/testing.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
distribution: 'temurin'
2121
- uses: gradle/gradle-build-action@v2
2222
with:
23-
arguments: clean assemble -x signArchives --stacktrace
23+
arguments: clean assemble --stacktrace
2424

2525
test:
2626
needs: build
@@ -55,4 +55,4 @@ jobs:
5555
run: test -f build/reports/codenarc/main.txt && cat build/reports/codenarc/main.txt
5656
- name: echo codenarcTest reports
5757
if: failure()
58-
run: test -f build/reports/codenarc/test.txt && cat build/reports/codenarc/test.txt
58+
run: test -f build/reports/codenarc/test.txt && cat build/reports/codenarc/test.txt

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildscript {
3131
```
3232

3333
To try out the head version, you can download the source and build it
34-
with ``./gradlew install -x test`` (we skip tests here because they
34+
with ``./gradlew publishToMavenLocal -x test`` (we skip tests here because they
3535
require Android SDK), then:
3636

3737
```gradle

RELEASING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Releasing
5555
3. Publish artifacts:
5656
- Run `git checkout v$RELEASE_VERSION`.
5757
- Release on Maven Central:
58-
- Run `./gradlew uploadArchives`.
58+
- Run `./gradlew publish`.
5959
- Go to the [OSSRH site](https://oss.sonatype.org), under “Staging Repositories”, close and release the
6060
artifact.
6161
- Release on Gradle Plugin Portal:

build.gradle

+47-40
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ apply plugin: 'idea'
2828
apply plugin: 'eclipse'
2929
apply plugin: 'groovy'
3030
apply plugin: 'maven'
31+
apply plugin: 'maven-publish'
3132
apply plugin: 'signing'
3233
apply plugin: 'com.jfrog.bintray'
3334
apply plugin: 'com.gradle.plugin-publish'
@@ -87,66 +88,72 @@ task javadocJar(type: Jar, dependsOn:javadoc) {
8788
from javadoc.destinationDir
8889
}
8990

90-
artifacts {
91-
archives sourcesJar
92-
archives groovydocJar
93-
archives javadocJar
94-
}
95-
9691
codenarc {
9792
toolVersion = "1.4"
9893
}
9994

100-
// The Gradle plugin portal doesn't allow signature files.
101-
if (!gradle.startParameter.taskNames.intersect(['publishPlugins'])) {
102-
signing {
103-
required { isReleaseVersion }
104-
sign configurations.archives
105-
}
106-
}
107-
10895
sourceCompatibility = JavaVersion.VERSION_1_7
10996
targetCompatibility = JavaVersion.VERSION_1_7
11097

111-
uploadArchives {
112-
repositories {
113-
mavenDeployer {
114-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
115-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
116-
if (rootProject.hasProperty("ossrhUsername") && rootProject.hasProperty("ossrhPassword")) {
117-
authentication(userName: ossrhUsername, password: ossrhPassword)
118-
}
119-
}
120-
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
121-
if (rootProject.hasProperty("ossrhUsername") && rootProject.hasProperty("ossrhPassword")) {
122-
authentication(userName: ossrhUsername, password: ossrhPassword)
123-
}
124-
}
125-
pom.project {
126-
name project.name
127-
description "Gradle build plugin to handle Protocol Buffers automated code generation and compilation"
128-
url "https://github.com/google/protobuf-gradle-plugin"
98+
tasks.withType(GenerateModuleMetadata) {
99+
enabled = false
100+
}
101+
102+
publishing {
103+
publications {
104+
pluginMaven(MavenPublication) {
105+
artifact sourcesJar
106+
artifact groovydocJar
107+
artifact javadocJar
108+
109+
pom {
110+
name = project.name
111+
description = "Gradle build plugin to handle Protocol Buffers automated code generation and compilation"
112+
url = "https://github.com/google/protobuf-gradle-plugin"
129113
licenses {
130114
license {
131-
name "BSD 3-Clause"
132-
url "http://opensource.org/licenses/BSD-3-Clause"
115+
name = "BSD 3-Clause"
116+
url = "http://opensource.org/licenses/BSD-3-Clause"
133117
}
134118
}
135119
developers {
136120
developer {
137-
id "zhangkun83"
138-
name "Kun Zhang"
139-
121+
id = "zhangkun83"
122+
name = "Kun Zhang"
123+
140124
}
141125
}
142126
scm {
143-
connection "scm:git:git://github.com/google/protobuf-gradle-plugin.git"
144-
developerConnection "scm:git:[email protected]:google/protobuf-gradle-plugin.git"
145-
url "https://github.com/google/protobuf-gradle-plugin"
127+
connection = "scm:git:git://github.com/google/protobuf-gradle-plugin.git"
128+
developerConnection = "scm:git:[email protected]:google/protobuf-gradle-plugin.git"
129+
url = "https://github.com/google/protobuf-gradle-plugin"
146130
}
147131
}
148132
}
149133
}
134+
135+
repositories {
136+
maven {
137+
String releaseUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
138+
String snapshotUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
139+
url = version.endsWith('SNAPSHOT') ? snapshotUrl : releaseUrl
140+
141+
credentials {
142+
if (rootProject.hasProperty("ossrhUsername") && rootProject.hasProperty("ossrhPassword")) {
143+
username = rootProject.ossrhUsername
144+
password = rootProject.ossrhPassword
145+
}
146+
}
147+
}
148+
}
149+
}
150+
151+
// The Gradle plugin portal doesn't allow signature files.
152+
if (!gradle.startParameter.taskNames.intersect(['publishPlugins'])) {
153+
signing {
154+
required { isReleaseVersion }
155+
sign publishing.publications.pluginMaven
156+
}
150157
}
151158

152159
pluginBundle {

0 commit comments

Comments
 (0)