Gradle tweaks (#3575)

* Use idiomatic repository declarations

* Prefer Maven Central to JCenter
* Limit JCenter to kotlinx-html-jvm module only
* Remove unnecessary repository declarations

* Agree to build scan T&Cs in settings where the plugin is applied

* Refactor

* Fix some issues in the build config examples

* Apply binary-compatibility-validator plugin only in subprojects that need it

* Don't configure Java source/target compatibility

There's no Java source code in the repository

* Don't unnecessarily declare plugins in root project build
This commit is contained in:
Matthew Haughton
2021-03-20 20:56:57 +11:00
committed by GitHub
parent 63dcfa04af
commit 866eb2b2f3
9 changed files with 77 additions and 77 deletions

View File

@@ -77,9 +77,9 @@ buildscript {
mavenCentral()
jcenter {
content {
// just allow to include kotlinx projects
// detekt needs 'kotlinx-html' for the html report
includeGroup "org.jetbrains.kotlinx"
// Only download the 'kotlinx-html-jvm' module from JCenter, but nothing else.
// detekt needs 'kotlinx-html-jvm' for the HTML report.
includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm")
}
}
}
@@ -103,17 +103,17 @@ detekt {
}
// Groovy dsl
tasks.detekt.jvmTarget = "1.8"
// Groovy DSL
tasks.withType(Detekt).configureEach {
jvmTarget = "1.8"
}
// or
// Kotlin dsl
tasks {
withType<Detekt> {
// Target version of the generated JVM bytecode. It is used for type resolution.
this.jvmTarget = "1.8"
}
// Kotlin DSL
tasks.withType<Detekt>.configureEach {
// Target version of the generated JVM bytecode. It is used for type resolution.
jvmTarget = "1.8"
}
```
@@ -128,7 +128,7 @@ which can be easily added to the Gradle configuration:
```kotlin
dependencies {
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:[version]"
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[version]")
}
```

View File

@@ -4,20 +4,8 @@ plugins {
packaging
releasing
detekt
id("org.jetbrains.dokka") apply false
id("com.github.johnrengelman.shadow") apply false
id("com.github.ben-manes.versions")
id("org.sonarqube")
id("binary-compatibility-validator")
}
repositories {
jcenter()
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
allprojects {
@@ -27,17 +15,17 @@ allprojects {
jacoco.toolVersion = Versions.JACOCO
val examplesOrTestUtils = setOf(
"detekt-bom",
"detekt-test",
"detekt-test-utils",
"detekt-sample-extensions"
)
tasks {
jacocoTestReport {
executionData.setFrom(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))
val examplesOrTestUtils = setOf(
"detekt-bom",
"detekt-test",
"detekt-test-utils",
"detekt-sample-extensions"
)
subprojects
.filterNot { it.name in examplesOrTestUtils }
.forEach {
@@ -51,9 +39,3 @@ tasks {
}
}
}
apiValidation {
// We need to perform api validations for external APIs, for :detekt-api and :detekt-psi-utils
ignoredProjects.addAll(subprojects.filter { it.name !in listOf("detekt-api", "detekt-psi-utils") }.map { it.name })
ignoredPackages.add("io.gitlab.arturbosch.detekt.api.internal")
}

View File

@@ -8,9 +8,8 @@ kotlinDslPluginOptions {
repositories {
mavenLocal() // used to publish and test local gradle plugin changes
gradlePluginPortal()
mavenCentral()
jcenter()
gradlePluginPortal()
}
object Plugins {
@@ -23,7 +22,7 @@ object Plugins {
const val DOKKA = "1.4.10"
const val SEMVER4J = "3.1.0"
const val NEXUS = "0.22.0"
const val KOTLIN_API_VALIDATOR = "0.3.0"
const val KOTLIN_API_VALIDATOR = "0.4.0"
}
dependencies {

View File

@@ -8,15 +8,6 @@ plugins {
jacoco
}
repositories {
jcenter()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// bundle detekt's version for all jars to use it at runtime
tasks.withType<Jar>().configureEach {
manifest {
@@ -55,14 +46,16 @@ tasks.withType<Test>().configureEach {
tasks.withType<KotlinCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
kotlinOptions.jvmTarget = Versions.JVM_TARGET
kotlinOptions.languageVersion = "1.4"
kotlinOptions.freeCompilerArgs = listOf(
"-progressive",
"-Xopt-in=kotlin.RequiresOptIn"
)
// Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
kotlinOptions.allWarningsAsErrors = project.findProperty("warningsAsErrors") == "true"
kotlinOptions {
jvmTarget = Versions.JVM_TARGET
languageVersion = "1.4"
freeCompilerArgs = listOf(
"-progressive",
"-Xopt-in=kotlin.RequiresOptIn"
)
// Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
allWarningsAsErrors = project.findProperty("warningsAsErrors") == "true"
}
}
dependencies {

View File

@@ -45,19 +45,20 @@ fun updateVersion(increment: (Semver) -> Semver) {
}
versionsFile.writeText("$newContent\n")
}
tasks {
register("incrementPatch") { doLast { updateVersion { it.nextPatch() } } }
register("incrementMinor") { doLast { updateVersion { it.nextMinor() } } }
register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } }
val incrementPatch by tasks.registering { doLast { updateVersion { it.nextPatch() } } }
val incrementMinor by tasks.registering { doLast { updateVersion { it.nextMinor() } } }
val incrementMajor by tasks.registering { doLast { updateVersion { it.nextMajor() } } }
register<UpdateVersionInFileTask>("applyDocVersion") {
fileToUpdate = file("${rootProject.rootDir}/docs/_config.yml")
linePartToFind = "detekt_version:"
lineTransformation = { "detekt_version: ${Versions.DETEKT}" }
}
val applyDocVersion by tasks.registering(UpdateVersionInFileTask::class) {
fileToUpdate = file("${rootProject.rootDir}/docs/_config.yml")
linePartToFind = "detekt_version:"
lineTransformation = { "detekt_version: ${Versions.DETEKT}" }
}
val applySelfAnalysisVersion by tasks.registering(UpdateVersionInFileTask::class) {
fileToUpdate = file("${rootProject.rootDir}/buildSrc/build.gradle.kts")
linePartToFind = "const val DETEKT ="
lineTransformation = { """ const val DETEKT = "${Versions.DETEKT}"""" }
register<UpdateVersionInFileTask>("applySelfAnalysisVersion") {
fileToUpdate = file("${rootProject.rootDir}/buildSrc/build.gradle.kts")
linePartToFind = "const val DETEKT ="
lineTransformation = { """ const val DETEKT = "${Versions.DETEKT}"""" }
}
}

View File

@@ -4,6 +4,7 @@ plugins {
module
id("org.jetbrains.dokka")
`java-test-fixtures`
id("binary-compatibility-validator")
}
dependencies {
@@ -30,3 +31,7 @@ listOf(configurations.testFixturesApiElements, configurations.testFixturesRuntim
tasks.withType<DokkaTask>().configureEach {
outputDirectory.set(rootDir.resolve("docs/pages/kdoc"))
}
apiValidation {
ignoredPackages.add("io.gitlab.arturbosch.detekt.api.internal")
}

View File

@@ -5,7 +5,14 @@ plugins {
}
repositories {
mavenCentral()
google()
jcenter {
content {
includeModule("org.jetbrains.trove4j", "trove4j")
includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm")
}
}
}
val intTest: Configuration by configurations.creating

View File

@@ -1,5 +1,6 @@
plugins {
module
id("binary-compatibility-validator")
}
dependencies {

View File

@@ -31,14 +31,26 @@ include(
"detekt-tooling"
)
pluginManagement {
repositories {
gradlePluginPortal()
}
}
// build scan plugin can only be applied in settings file
plugins {
id("com.gradle.enterprise") version "3.3.1"
}
gradleEnterprise {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
jcenter {
content {
includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm")
includeGroup("org.jetbrains.dokka")
}
}
}
}