Skip to content

Commit 22b78a7

Browse files
committed
Update to the latest config. Switch to Java 11 in build.gradle.
1 parent b94249b commit 22b78a7

28 files changed

+809
-313
lines changed

.github/workflows/build-on-windows.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ jobs:
2020

2121
- name: Build project and run tests
2222
shell: cmd
23-
run: gradlew.bat build --stacktrace
23+
# For the reason on `--no-daemon` see https://github.com/actions/cache/issues/454
24+
run: gradlew.bat build --stacktrace --no-daemon

.idea/codeStyles/Project.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

+25-17
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ import io.spine.internal.gradle.applyGitHubPackages
5151
import io.spine.internal.gradle.applyStandard
5252
import io.spine.internal.gradle.forceVersions
5353
import io.spine.internal.gradle.github.pages.updateGitHubPages
54+
import io.spine.internal.gradle.javac.configureErrorProne
55+
import io.spine.internal.gradle.javac.configureJavac
5456
import io.spine.internal.gradle.publish.PublishingRepos
5557
import io.spine.internal.gradle.report.license.LicenseReporter
5658
import io.spine.internal.gradle.report.pom.PomGenerator
5759
import io.spine.internal.gradle.spinePublishing
60+
import io.spine.internal.gradle.testing.configureLogging
61+
import io.spine.internal.gradle.testing.registerTestTasks
5862
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5963

6064
@Suppress("RemoveRedundantQualifierName") // Cannot use imports here.
@@ -98,7 +102,7 @@ plugins {
98102
}
99103
@Suppress("RemoveRedundantQualifierName") // Cannot use imports here.
100104
io.spine.internal.dependency.ErrorProne.GradlePlugin.apply {
101-
id(id) version version
105+
id(id)
102106
}
103107
}
104108

@@ -134,26 +138,32 @@ allprojects {
134138
}
135139

136140
subprojects {
141+
142+
val spineBaseVersion: String by extra
143+
val spineCoreVersion: String by extra
144+
137145
apply {
138146
plugin("java-library")
139147
plugin("kotlin")
140148
plugin("com.google.protobuf")
141149
plugin("net.ltgt.errorprone")
142150
plugin("pmd")
143151
plugin("maven-publish")
144-
}
145152

146-
apply {
147153
// Apply custom Kotlin script plugins.
148154
plugin("pmd-settings")
149-
// Apply Groovy-based script plugins.
150-
with(Scripts) {
151-
from(testOutput(project))
152-
from(javacArgs(project))
153-
}
154155
}
155156

156-
LicenseReporter.generateReportIn(project)
157+
tasks {
158+
withType<JavaCompile> {
159+
configureJavac()
160+
configureErrorProne()
161+
}
162+
withType<Test> {
163+
configureLogging()
164+
}
165+
registerTestTasks()
166+
}
157167

158168
with(repositories) {
159169
applyGitHubPackages("base", rootProject)
@@ -163,19 +173,18 @@ subprojects {
163173
applyStandard()
164174
}
165175

176+
LicenseReporter.generateReportIn(project)
166177
JavadocConfig.applyTo(project)
167-
168-
val spineBaseVersion: String by extra
169-
val spineCoreVersion: String by extra
170-
171178
updateGitHubPages(spineBaseVersion) {
172179
allowInternalJavadoc.set(true)
173180
rootFolder.set(rootDir)
174181
}
175182

183+
val javaVersion = JavaVersion.VERSION_11
184+
176185
java {
177-
sourceCompatibility = JavaVersion.VERSION_1_8
178-
targetCompatibility = JavaVersion.VERSION_1_8
186+
sourceCompatibility = javaVersion
187+
targetCompatibility = javaVersion
179188
}
180189

181190
kotlin {
@@ -184,15 +193,14 @@ subprojects {
184193

185194
tasks.withType<KotlinCompile>().configureEach {
186195
kotlinOptions {
187-
jvmTarget = JavaVersion.VERSION_1_8.toString()
196+
jvmTarget = javaVersion.toString()
188197
freeCompilerArgs = listOf("-Xskip-prerelease-check")
189198
}
190199
}
191200

192201
dependencies {
193202
ErrorProne.apply {
194203
errorprone(core)
195-
errorproneJavac(javacPlugin)
196204
}
197205

198206
Protobuf.libs.forEach { api(it) }

buildSrc/build.gradle.kts

+19-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ repositories {
4848
mavenCentral()
4949
}
5050

51-
val jacksonVersion = "2.11.0"
51+
/**
52+
* The version of Jackson used by `buildSrc`.
53+
*
54+
* Please keep this value in sync. with `io.spine.internal.dependency.Jackson.version`.
55+
* It's not a requirement, but would be good in terms of consistency.
56+
*/
57+
val jacksonVersion = "2.13.0"
58+
5259
val googleAuthToolVersion = "2.1.2"
5360
val licenseReportVersion = "2.0"
5461
val grGitVersion = "3.1.1"
@@ -61,6 +68,16 @@ val grGitVersion = "3.1.1"
6168
*/
6269
val guavaVersion = "30.1.1-jre"
6370

71+
/**
72+
* The version of ErrorProne Gradle plugin.
73+
*
74+
* Please keep in sync. with `io.spine.internal.dependency.ErrorProne.GradlePlugin.version`.
75+
*
76+
* @see <a href="https://github.com/tbroyer/gradle-errorprone-plugin/releases">
77+
* Error Prone Gradle Plugin Releases</a>
78+
*/
79+
val errorProneVersion = "2.0.2"
80+
6481
dependencies {
6582
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion")
6683
implementation("com.google.cloud.artifactregistry:artifactregistry-auth-common:$googleAuthToolVersion") {
@@ -69,4 +86,5 @@ dependencies {
6986
implementation("com.google.guava:guava:$guavaVersion")
7087
api("com.github.jk1:gradle-license-report:$licenseReportVersion")
7188
implementation("org.ajoberstar.grgit:grgit-core:${grGitVersion}")
89+
implementation("net.ltgt.gradle:gradle-errorprone-plugin:${errorProneVersion}")
7290
}

buildSrc/src/main/groovy/javac-args.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
* This script configures Java Compiler.
2929
*/
3030

31+
println("`javac-args.gradle` script is deprecated. Please use `JavaCompile.configureJavac()` " +
32+
"and `JavaCompile.configureErrorProne()` utilities instead.")
33+
3134
tasks.withType(JavaCompile) {
3235

3336
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {

buildSrc/src/main/groovy/slow-tests.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27+
println("`slow-tests.gradle` script is deprecated. " +
28+
"Please use `TaskContainer.registerTestTasks()` instead.")
29+
2730
final def slowTag = 'slow' // See io.spine.testing.SlowTest
2831

2932
task fastTest(type: Test) {

buildSrc/src/main/groovy/test-artifacts.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
//
3030
// testCompile project(path: ":projectWithTests", configuration: 'testArtifacts')
3131
//
32+
33+
println("`test-artifacts.gradle` script is deprecated. " +
34+
"Please use the `Project.exposeTestArtifacts()` utility instead.")
35+
3236
configurations {
3337
testArtifacts.extendsFrom testRuntime
3438
}

buildSrc/src/main/groovy/test-output.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* of tests and their results.
3434
*/
3535

36+
println("`test-output.gradle` script is deprecated. Please use `Test.configureLogging()` instead.")
37+
3638
tasks.withType(Test).each {
3739
it.testLogging {
3840
showStandardStreams = true

buildSrc/src/main/kotlin/io/spine/internal/dependency/ErrorProne.kt

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ object ErrorProne {
4646
// https://github.com/tbroyer/gradle-errorprone-plugin/releases
4747
object GradlePlugin {
4848
const val id = "net.ltgt.errorprone"
49+
/**
50+
* The version of this plugin is already specified in `buildSrc/build.gradle.kts` file.
51+
* Thus, when applying the plugin in projects build files, only the [id] should be used.
52+
*
53+
* When the plugin is used as a library (e.g. in tools), its version and the library
54+
* artifacts are of importance.
55+
*/
4956
const val version = "2.0.2"
5057
const val lib = "net.ltgt.gradle:gradle-errorprone-plugin:${version}"
5158
}

buildSrc/src/main/kotlin/io/spine/internal/dependency/Jackson.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package io.spine.internal.dependency
2828

2929
@Suppress("unused")
3030
object Jackson {
31-
private const val version = "2.12.4"
31+
private const val version = "2.13.0"
3232
// https://github.com/FasterXML/jackson-core
3333
const val core = "com.fasterxml.jackson.core:jackson-core:${version}"
3434
// https://github.com/FasterXML/jackson-databind

buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotlin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ package io.spine.internal.dependency
3030
// https://github.com/Kotlin
3131
object Kotlin {
3232
@Suppress("MemberVisibilityCanBePrivate") // used directly from outside
33-
const val version = "1.5.30"
33+
const val version = "1.5.31"
3434
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:${version}"
3535
const val stdLib = "org.jetbrains.kotlin:kotlin-stdlib:${version}"
3636
const val stdLibCommon = "org.jetbrains.kotlin:kotlin-stdlib-common:${version}"

buildSrc/src/main/kotlin/io/spine/internal/gradle/StringExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ package io.spine.internal.gradle
3131
* `false` otherwise.
3232
*/
3333
fun String.isSnapshot(): Boolean {
34-
return contains("snapshot", true)
34+
return contains("snapshot", ignoreCase = true)
3535
}

buildSrc/src/main/kotlin/io/spine/internal/gradle/checkstyle/CheckStyleConfig.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ object CheckStyleConfig {
5757
plugin(CheckstylePlugin::class.java)
5858
}
5959

60+
val configDir = project.rootDir.resolve("config/quality/")
61+
6062
with(project.the<CheckstyleExtension>()) {
6163
toolVersion = CheckStyle.version
62-
configFile = project.rootDir.resolve("config/quality/checkstyle.xml")
64+
configDirectory.set(configDir)
6365
}
6466

6567
project.afterEvaluate {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2021, TeamDev. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Redistribution and use in source and/or binary forms, with or without
11+
* modification, must retain the above copyright notice and the following
12+
* disclaimer.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
package io.spine.internal.gradle.javac
28+
29+
import net.ltgt.gradle.errorprone.errorprone
30+
import org.gradle.api.tasks.compile.JavaCompile
31+
import org.gradle.process.CommandLineArgumentProvider
32+
33+
/**
34+
* Configures Error Prone for this `JavaCompile` task.
35+
*
36+
* Specifies the arguments for the compiler invocations. In particular, this configuration
37+
* overrides a number of Error Prone defaults. See [ErrorProneConfig] for the details.
38+
*
39+
* Please note that while `ErrorProne` is a standalone Gradle plugin,
40+
* it still has to be configured through `JavaCompile` task options.
41+
*
42+
* Here's an example of how to use it:
43+
*
44+
* ```
45+
* tasks {
46+
* withType<JavaCompile> {
47+
* configureErrorProne()
48+
* }
49+
* }
50+
*```
51+
*/
52+
fun JavaCompile.configureErrorProne() {
53+
options.errorprone
54+
.errorproneArgumentProviders
55+
.add(ErrorProneConfig.ARGUMENTS)
56+
}
57+
58+
/**
59+
* The knowledge that is required to set up `Error Prone`.
60+
*/
61+
private object ErrorProneConfig {
62+
63+
/**
64+
* Command line options for the `Error Prone` compiler.
65+
*/
66+
val ARGUMENTS = CommandLineArgumentProvider {
67+
listOf(
68+
69+
// Exclude generated sources from being analyzed by ErrorProne.
70+
"-XepExcludedPaths:.*/generated/.*",
71+
72+
// Turn the check off until ErrorProne can handle `@Nested` JUnit classes.
73+
// See issue: https://github.com/google/error-prone/issues/956
74+
"-Xep:ClassCanBeStatic:OFF",
75+
76+
// Turn off checks that report unused methods and method parameters.
77+
// See issue: https://github.com/SpineEventEngine/config/issues/61
78+
"-Xep:UnusedMethod:OFF",
79+
"-Xep:UnusedVariable:OFF",
80+
81+
"-Xep:CheckReturnValue:OFF",
82+
"-Xep:FloggerSplitLogStatement:OFF",
83+
)
84+
}
85+
}

0 commit comments

Comments
 (0)