Skip to content

Commit

Permalink
Prepare artifact publishing on 1.x branch (#1673)
Browse files Browse the repository at this point in the history
* Switch to the Vanniktech base plugin for publishing (#1450)

* Switch to the Vanniktech base plugin for publishing

Move configuration out of build.gradle files and into build.gradle.kts files.
Sign published builds.
Support publishing release builds from GitHub actions.

* Update build.gradle.kts

Co-authored-by: Zac Sweers <zac.sweers@gmail.com>

Co-authored-by: Zac Sweers <zac.sweers@gmail.com>

* Move modules to match artifact names

* Fixup some style problems

---------

Co-authored-by: Zac Sweers <zac.sweers@gmail.com>
  • Loading branch information
swankjesse and ZacSweers committed May 12, 2023
1 parent 8f951b0 commit 4109c5a
Show file tree
Hide file tree
Showing 61 changed files with 212 additions and 157 deletions.
20 changes: 0 additions & 20 deletions adapters/gradle.properties

This file was deleted.

86 changes: 60 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import com.diffplug.gradle.spotless.JavaExtension
import org.gradle.jvm.tasks.Jar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -35,12 +36,21 @@ buildscript {
}

plugins {
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.mavenPublish)
alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless)
alias(libs.plugins.japicmp) apply false
}

allprojects {
group = "com.squareup.moshi"
version = "1.15.0-SNAPSHOT"

repositories {
mavenCentral()
}
}

spotless {
format("misc") {
target("*.md", ".gitignore")
Expand All @@ -54,7 +64,11 @@ spotless {
java {
configureCommonJavaFormat()
target("**/*.java")
targetExclude("**/build/**",)
targetExclude(
"**/build/**",
"**/RecordsTest.java",
"**/RecordJsonAdapter.java",
)
}
kotlin {
ktlint(libs.versions.ktlint.get()).userData(mapOf("indent_size" to "2"))
Expand All @@ -72,10 +86,6 @@ spotless {
}

subprojects {
repositories {
mavenCentral()
}

// Apply with "java" instead of just "java-library" so kotlin projects get it too
pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
Expand Down Expand Up @@ -106,30 +116,54 @@ subprojects {
}
}
}
}

// Configure publishing
pluginManager.withPlugin("com.vanniktech.maven.publish") {
// Configure automatic-module-name, but only for published modules
@Suppress("UnstableApiUsage")
val automaticModuleName = providers.gradleProperty("AUTOMATIC_MODULE_NAME")
.forUseAtConfigurationTime()
if (automaticModuleName.isPresent) {
val name = automaticModuleName.get()
tasks.withType<Jar>().configureEach {
manifest {
attributes("Automatic-Module-Name" to name)
allprojects {
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
perPackageOption {
matchingRegex.set("com\\.squareup.moshi\\.internal.*")
suppress.set(true)
}
}
if (name == "dokkaHtml") {
outputDirectory.set(rootDir.resolve("docs/1.x"))
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
externalDocumentationLink {
url.set(URL("https://square.github.io/okio/2.x/okio/"))
}
}
}
}

if (name != "codegen" && pluginManager.hasPlugin("org.jetbrains.kotlin.jvm")) {
apply(plugin = "org.jetbrains.dokka")
tasks.named<DokkaTask>("dokkaHtml") {
outputDirectory.set(rootDir.resolve("docs/1.x"))
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
externalDocumentationLink {
url.set(URL("https://square.github.io/okio/2.x/okio/"))
plugins.withId("com.vanniktech.maven.publish.base") {
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
signAllPublications()
pom {
description.set("A modern JSON API for Android and Java")
name.set(project.name)
url.set("https://github.com/square/moshi/")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/square/moshi/")
connection.set("scm:git:git://github.com/square/moshi.git")
developerConnection.set("scm:git:ssh://git@github.com/square/moshi.git")
}
developers {
developer {
id.set("square")
name.set("Square, Inc.")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ plugins {
}

dependencies {
kapt(project(":kotlin:codegen"))
kapt(project(":moshi-kotlin-codegen"))
compileOnly(libs.jsr305)
implementation(project(":moshi"))
implementation(project(":adapters"))
implementation(project(":moshi-adapters"))
}
18 changes: 0 additions & 18 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,3 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 \
--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

kapt.include.compile.classpath=false

GROUP=com.squareup.moshi
VERSION_NAME=1.15.0-SNAPSHOT
POM_DESCRIPTION=A modern JSON API for Android and Java
POM_URL=https://github.com/square/moshi/
POM_SCM_URL=https://github.com/square/moshi/
POM_SCM_CONNECTION=scm:git:git://github.com/square/moshi.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/square/moshi.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.
POM_DEVELOPER_URL=https://github.com/square/
POM_INCEPTION_YEAR=2015
SONATYPE_STAGING_PROFILE=com.squareup
SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[versions]
autoService = "1.0"
gjf = "1.11.0"
gjf = "1.17.0"
jvmTarget = "1.8"
kotlin = "1.8.21"
kotlinCompileTesting = "0.2.1"
Expand All @@ -26,7 +26,7 @@ ktlint = "0.41.0"
dokka = { id = "org.jetbrains.dokka", version = "1.8.10" }
japicmp = { id = "me.champeau.gradle.japicmp", version = "0.2.9" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.21.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.2" }
mavenShadow = { id = "com.github.johnrengelman.shadow", version = "7.0.0" }
spotless = { id = "com.diffplug.spotless", version = "5.14.2" }

Expand Down
19 changes: 0 additions & 19 deletions kotlin/codegen/gradle.properties

This file was deleted.

20 changes: 0 additions & 20 deletions kotlin/reflect/gradle.properties

This file was deleted.

6 changes: 3 additions & 3 deletions kotlin/tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ dependencies {
// Do nothing
}
KAPT -> {
"kaptTest"(project(":kotlin:codegen"))
"kaptTest"(project(":moshi-kotlin-codegen"))
}
KSP -> {
"kspTest"(project(":kotlin:codegen"))
"kspTest"(project(":moshi-kotlin-codegen"))
}
}
testImplementation(project(":moshi"))
testImplementation(project(":kotlin:reflect"))
testImplementation(project(":moshi-kotlin"))
testImplementation(project(":kotlin:tests:extra-moshi-test-module"))
testImplementation(kotlin("reflect"))
testImplementation(libs.junit)
Expand Down
8 changes: 4 additions & 4 deletions kotlin/tests/codegen-only/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ dependencies {
when (testMode) {
REFLECT -> {
// Default to KSP in this case, this is a CI-only thing
"kspTest"(project(":kotlin:codegen"))
"kspTest"(project(":moshi-kotlin-codegen"))
}
KAPT -> {
"kaptTest"(project(":kotlin:codegen"))
"kaptTest"(project(":moshi-kotlin-codegen"))
}
KSP -> {
"kspTest"(project(":kotlin:codegen"))
"kspTest"(project(":moshi-kotlin-codegen"))
}
}
testImplementation(project(":moshi"))
testImplementation(project(":kotlin:reflect"))
testImplementation(project(":moshi-kotlin"))
testImplementation(project(":kotlin:tests:extra-moshi-test-module"))
testImplementation(kotlin("reflect"))
testImplementation(libs.junit)
Expand Down
File renamed without changes.
18 changes: 17 additions & 1 deletion adapters/build.gradle.kts → moshi-adapters/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import com.vanniktech.maven.publish.JavadocJar.Javadoc
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.gradle.jvm.tasks.Jar

/*
* Copyright (C) 2020 Square, Inc.
*
Expand All @@ -16,7 +21,8 @@

plugins {
kotlin("jvm")
id("com.vanniktech.maven.publish")
id("com.vanniktech.maven.publish.base")
id("org.jetbrains.dokka")
}

dependencies {
Expand All @@ -27,3 +33,13 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.truth)
}

tasks.withType<Jar>().configureEach {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.moshi.adapters")
}
}

configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = Javadoc()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
isTransitive = false
isForce = true
}
latest(project(":adapters"))
latest(project(":moshi-adapters"))
}

val japicmp = tasks.register<JapicmpTask>("japicmp") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static final class PolymorphicJsonAdapter extends JsonAdapter<Object> {

/** Single-element options containing the label's key only. */
final JsonReader.Options labelKeyOptions;

/** Corresponds to subtypes. */
final JsonReader.Options labelOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import com.vanniktech.maven.publish.JavadocJar.None
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("com.google.devtools.ksp")
id("com.vanniktech.maven.publish")
id("com.vanniktech.maven.publish.base")
alias(libs.plugins.mavenShadow)
}

Expand Down Expand Up @@ -123,3 +126,7 @@ artifacts {
runtimeOnly(shadowJar)
archives(shadowJar)
}

configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = None()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
* limitations under the License.
*/

import com.vanniktech.maven.publish.JavadocJar.Javadoc
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.gradle.jvm.tasks.Jar

plugins {
kotlin("jvm")
id("com.vanniktech.maven.publish")
id("com.vanniktech.maven.publish.base")
id("org.jetbrains.dokka")
}

dependencies {
Expand All @@ -27,3 +33,13 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.truth)
}

tasks.withType<Jar>().configureEach {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.moshi.kotlin")
}
}

configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = Javadoc()))
}

0 comments on commit 4109c5a

Please sign in to comment.