Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize build logic. #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ on:
jobs:
build:
name: JDK ${{ matrix.java_version }}
runs-on: macOS-latest
runs-on: macos-13
strategy:
matrix:
java_version: [11]
java_version: [17]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
abi: x86
- name: Full check
run: ./gradlew check --stacktrace
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: Sample App
path: sample/build/outputs
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
53 changes: 53 additions & 0 deletions conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.android.library.plugin)
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"
37 changes: 37 additions & 0 deletions conventions/src/main/kotlin/android-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.
*/
plugins {
id("com.android.library")
}

android {
compileSdk = 34

defaultConfig {
minSdk = 19
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
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")
}
}
}
}
}
Loading
Loading