Skip to content

Commit

Permalink
- Move to Version Catalogs.
Browse files Browse the repository at this point in the history
- Use precompiled scripts for common build logic.
- Bump library versions.
- Bump Gradle version.
- Use JVM Toolchain (Java 11).
- Resolve IDE warnings that has an obviously safe resolution: finalize vars, use try-with-resources, etc, when applicable.
  • Loading branch information
psteiger committed Sep 23, 2024
1 parent ee0fce2 commit a87f165
Show file tree
Hide file tree
Showing 41 changed files with 480 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: macos-13
strategy:
matrix:
java_version: [11]
java_version: [17]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install JDK 11
- name: Install JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
- name: Cache gradle packages
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
protosimplestore/test
*.iml
.gradle
/local.properties
Expand Down
93 changes: 10 additions & 83 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import net.ltgt.gradle.errorprone.CheckSeverity
import org.jetbrains.dokka.gradle.DokkaTaskPartial

buildscript {
apply from: rootProject.file('gradle/dependencies.gradle')
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath "com.android.tools.build:gradle:${deps.build.gradlePlugins.android}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${deps.build.gradlePlugins.kotlin}"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:${deps.build.gradlePlugins.errorProne}"
classpath "net.ltgt.gradle:gradle-nullaway-plugin:${deps.build.gradlePlugins.nullAway}"
classpath "com.diffplug.spotless:spotless-plugin-gradle:${deps.build.gradlePlugins.spotless}"
classpath "com.google.protobuf:protobuf-gradle-plugin:${deps.build.gradlePlugins.protobuf}"
classpath "com.vanniktech:gradle-maven-publish-plugin:${deps.build.gradlePlugins.mavenPublish}"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${deps.build.gradlePlugins.dokka}"
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.errorprone) apply false
alias(libs.plugins.nullaway) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.gradle.maven.publish) apply false
alias(libs.plugins.dokka) apply false
}

apply plugin: 'org.jetbrains.dokka'
Expand All @@ -26,68 +18,3 @@ tasks.dokkaHtmlMultiModule {
outputDirectory.set(new File(rootDir,"docs/0.x"))
includes.from(project.layout.projectDirectory.file("README.md"))
}

subprojects {
var isSample = project.name == "sample"
repositories {
google()
mavenCentral()
}

apply from: rootProject.file('gradle/dependencies.gradle')
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
format 'misc', {
target '**/*.md', '**/.gitignore'

indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
java {
target "**/*.java"
googleJavaFormat(deps.versions.gjf)
licenseHeaderFile rootProject.file('spotless/copyright.java')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target '**/*.gradle'
trimTrailingWhitespace()
endWithNewline()
}
}

apply plugin: 'net.ltgt.errorprone'
apply plugin: 'net.ltgt.nullaway'
dependencies {
errorproneJavac deps.build.errorProneJavac
errorprone deps.build.nullAway
errorprone deps.build.errorProne
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.nullaway {
severity = CheckSeverity.ERROR
annotatedPackages.add("com.uber")
unannotatedSubPackages.add("com.uber.simplestore.proto")
treatGeneratedAsUnannotated = true
}
options.errorprone.disableWarningsInGeneratedCode = true
}

if (!isSample) {
apply plugin: 'org.jetbrains.dokka'
tasks.withType(DokkaTaskPartial).configureEach {
outputDirectory.set(new File(buildDir, "docs/partial"))
moduleName.set(project.property("POM_ARTIFACT_ID").toString())
moduleVersion.set(project.property("VERSION_NAME").toString())
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

apply from: 'gradle/dependencies.gradle'
1 change: 1 addition & 0 deletions conventions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
alias(libs.plugins.spotless)
}

repositories {
google()
mavenCentral()
gradlePluginPortal()
}

spotless {
groovyGradle {
target("**/*.gradle")
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
target("**/*.gradle.kts")
trimTrailingWhitespace()
endWithNewline()
}
}

dependencies {
// Workaround for using version catalog on precompiled scripts.
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files((libs as Any).javaClass.superclass.protectionDomain.codeSource.location))
implementation(gradleApi())
implementation(libs.gradle.errorprone.plugin)
implementation(libs.gradle.nullaway.plugin)
implementation(libs.gradle.spotless.plugin)
implementation(libs.gradle.dokka.plugin)
implementation(libs.gradle.protobuf.plugin)
}
24 changes: 24 additions & 0 deletions conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "conventions"
26 changes: 26 additions & 0 deletions conventions/src/main/kotlin/dokka-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.dokka.gradle.DokkaTaskPartial

plugins {
id("org.jetbrains.dokka")
}

tasks.withType<DokkaTaskPartial>().configureEach {
outputDirectory.set(File(layout.buildDirectory.asFile.get().path, "docs/partial"))
moduleName.set(project.property("POM_ARTIFACT_ID").toString())
moduleVersion.set(project.property("VERSION_NAME").toString())
}
45 changes: 45 additions & 0 deletions conventions/src/main/kotlin/errorprone-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.errorprone
import net.ltgt.gradle.nullaway.nullaway
import org.gradle.accessors.dm.LibrariesForLibs

plugins {
id("net.ltgt.errorprone")
id("net.ltgt.nullaway")
}

val libs = the<LibrariesForLibs>()

dependencies {
errorproneJavac(libs.errorprone.javac)
errorprone(libs.errorprone)
errorprone(libs.nullaway)
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
disableWarningsInGeneratedCode = true

nullaway {
severity = CheckSeverity.ERROR
annotatedPackages.add("com.uber")
unannotatedSubPackages.add("com.uber.simplestore.proto")
treatGeneratedAsUnannotated = true
}
}
}
37 changes: 37 additions & 0 deletions conventions/src/main/kotlin/protobuf-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.accessors.dm.LibrariesForLibs

plugins {
id("com.google.protobuf")
}

val libs = the<LibrariesForLibs>()

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
create("java") {
option("lite")
}
}
}
}
}
49 changes: 49 additions & 0 deletions conventions/src/main/kotlin/spotless-convention.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.accessors.dm.LibrariesForLibs

plugins {
id("com.diffplug.spotless")
}

val libs = the<LibrariesForLibs>()

spotless {
format("misc") {
target("**/*.md", "**/.gitignore")
indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
java {
target("src/*/java/**/*.java")
googleJavaFormat(libs.versions.javaFormat.get())
licenseHeaderFile(rootProject.file("spotless/copyright.java"))
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target("**/*.gradle")
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
target("**/*.gradle.kts")
trimTrailingWhitespace()
endWithNewline()
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ GITHUB_DOWNLOAD_PREFIX=https\://github.com/uber/simple-store/releases/download/
GITHUB_BRANCH=master

SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
RELEASE_SIGNING_ENABLED=true
# will be removed in AGP 9.0
android.buildFeatures.buildConfig=true
Loading

0 comments on commit a87f165

Please sign in to comment.