Skip to content

Commit

Permalink
Improve Gradle build scripts (#3062)
Browse files Browse the repository at this point in the history
* Convert build.gradle.kts outliers back to build.gradle to be consistent
It also needs more hacky code than benefits.
Builds will be faster too.

* Remove unnecessary inclusion of dead repositories

* Remove dead repository, mavenLocal() is not used, because we depend on project() objects.

Even if it was, a repositories {} inside a build.gradle file doesn't override, it appends (confirmed with `println(repositories.collect())` before and after the block; so globally declared repos might win in resolution.

* Remove unused dependency

* Generalize ordering of build.gradle headings:
imports
plugins { }
apply from:
description
dependencies
... everything else

and make plugin syntax consistent.

Also fix ordering dependency on description being set before including a file.

* Add missing dependencies.gradle inclusions

* Format

* Introduce new module type: java-test

Change: junitJupiterExtensionTest and junitJupiterInlineMockMakerExtensionTest had the javadoc task enabled.

* Add java version to new module type: java-test

Change: memory-test, osgi-test, junitJupiterExtensionTest and junitJupiterInlineMockMakerExtensionTest had no java compatibility declared, now it's 11.

* Nominate more modules as java-test.

Change: extTest, junitJupiterParallelTest, groovyTest, groovyInlineTest had no java compatibility declared, now it's 11.

Change: extTest, junitJupiterParallelTest, groovyTest, groovyInlineTest, kotlinReleaseCoroutinesTest and kotlinTest had the javadoc task enabled.
  • Loading branch information
TWiStErRob committed Jul 15, 2023
1 parent f008531 commit a7bc931
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 168 deletions.
1 change: 0 additions & 1 deletion gradle/dependencies.gradle
Expand Up @@ -40,7 +40,6 @@ libraries.kotlin = [

stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3-native-mt',
gradlePlugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}",
]
libraries.android = [
runner: 'androidx.test:runner:1.5.2',
Expand Down
4 changes: 3 additions & 1 deletion gradle/java-publication.gradle
Expand Up @@ -52,7 +52,9 @@ publishing {

pom {
name = artifactId
description = project.description
afterEvaluate {
description = project.description
}

plugins.withId("java") {
//Gradle does not write 'jar' packaging to the pom (unlike other packaging types).
Expand Down
10 changes: 10 additions & 0 deletions gradle/java-test.gradle
@@ -0,0 +1,10 @@
apply plugin: "java"

// Test modules don't need to be published, so there's no need to build javadoc for them.
// Most test modules don't have src/main, but this is here in shared configuration just in case.
tasks.javadoc.enabled = false

java {
sourceCompatibility = 11
targetCompatibility = 11
}
18 changes: 6 additions & 12 deletions settings.gradle.kts
@@ -1,8 +1,9 @@
plugins {
id("com.gradle.enterprise").version("3.13.4")
id("com.gradle.enterprise") version "3.13.4"
}

include("subclass",
include(
"subclass",
"inlineTest",
"proxy",
"extTest",
Expand All @@ -20,7 +21,8 @@ include("subclass",
"osgi-test",
"bom",
"errorprone",
"programmatic-test")
"programmatic-test"
)

// https://developer.android.com/studio/command-line/variables#envar
// https://developer.android.com/studio/build#properties-files
Expand All @@ -32,18 +34,10 @@ if (System.getenv("ANDROID_HOME") != null || File("local.properties").exists())

rootProject.name = "mockito"

val koltinBuildScriptProject = hashSetOf("junitJupiterExtensionTest", "junitJupiterInlineMockMakerExtensionTest")

fun buildFileExtensionFor(projectName: String) =
if (projectName in koltinBuildScriptProject) ".gradle.kts" else ".gradle"

fun buildFileFor(projectName: String) =
"$projectName${buildFileExtensionFor(projectName)}"

rootProject.children.forEach { project ->
val projectDirName = "subprojects/${project.name}"
project.projectDir = File(settingsDir, projectDirName)
project.buildFileName = buildFileFor(project.name)
project.buildFileName = "${project.name}.gradle"
require(project.projectDir.isDirectory) {
"Project directory ${project.projectDir} for project ${project.name} does not exist."
}
Expand Down
5 changes: 3 additions & 2 deletions subprojects/android/android.gradle
@@ -1,7 +1,8 @@
description = "Mockito for Android"

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-library.gradle"

description = "Mockito for Android"

dependencies {
api project.rootProject
implementation libraries.bytebuddyandroid
Expand Down
2 changes: 1 addition & 1 deletion subprojects/bom/bom.gradle
@@ -1,5 +1,5 @@
plugins {
id('java-platform')
id 'java-platform'
}

description = "Mockito Bill of Materials (BOM)"
Expand Down
6 changes: 3 additions & 3 deletions subprojects/errorprone/errorprone.gradle
@@ -1,7 +1,7 @@
description = "ErrorProne plugins for Mockito"

apply from: "$rootDir/gradle/java-library.gradle"
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-library.gradle"

description = "ErrorProne plugins for Mockito"

dependencies {
compileOnly libraries.autoservice
Expand Down
6 changes: 1 addition & 5 deletions subprojects/extTest/extTest.gradle
@@ -1,12 +1,8 @@
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

apply plugin: 'java'
description = "End-to-end tests for Mockito and its extensions."

repositories {
mavenLocal() //we depend on locally published mockito
}

dependencies {
testImplementation project.rootProject
testImplementation project(":junit-jupiter")
Expand Down
9 changes: 6 additions & 3 deletions subprojects/groovyInlineTest/groovyInlineTest.gradle
@@ -1,8 +1,11 @@
apply plugin: 'groovy'

description = "Integration test for using mockito-inline with Groovy."
plugins {
id 'groovy'
}

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "Integration test for using mockito-inline with Groovy."

dependencies {
testImplementation project(":")
Expand Down
9 changes: 6 additions & 3 deletions subprojects/groovyTest/groovyTest.gradle
@@ -1,8 +1,11 @@
apply plugin: 'groovy'

description = "Integration test for using Mockito from Groovy."
plugins {
id 'groovy'
}

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "Integration test for using Mockito from Groovy."

dependencies {
testImplementation project(":")
Expand Down
14 changes: 2 additions & 12 deletions subprojects/inlineTest/inlineTest.gradle
@@ -1,24 +1,14 @@
plugins {
id 'java'
}

description = "Mockito preconfigured inline mock maker (intermediate and to be superseeded by automatic usage in a future version)"

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

java {
sourceCompatibility = 11
targetCompatibility = 11
}
description = "Mockito preconfigured inline mock maker (intermediate and to be superseeded by automatic usage in a future version)"

dependencies {
implementation project.rootProject
testImplementation libraries.junit4
testImplementation libraries.assertj
}

tasks.javadoc.enabled = false

test {
if (JavaVersion.VERSION_17 <= JavaVersion.current()) {
// For Java 17: https://openjdk.org/jeps/403
Expand Down
8 changes: 6 additions & 2 deletions subprojects/junit-jupiter/junit-jupiter.gradle
@@ -1,9 +1,13 @@
import aQute.bnd.gradle.Resolve

description = "Mockito JUnit 5 support"
plugins {
id 'biz.aQute.bnd.builder'
}

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-library.gradle"
apply plugin: 'biz.aQute.bnd.builder'

description = "Mockito JUnit 5 support"

dependencies {
api project.rootProject
Expand Down
@@ -0,0 +1,16 @@
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "End-to-end tests for automatic registration of MockitoExtension."

dependencies {
testImplementation project(":junit-jupiter")
testImplementation libraries.assertj
testImplementation libraries.junitJupiterApi
testRuntimeOnly libraries.junitJupiterEngine
testRuntimeOnly libraries.junitPlatformLauncher
}

test {
useJUnitPlatform()
}

This file was deleted.

@@ -0,0 +1,16 @@
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "End-to-end tests for automatic registration of MockitoExtension with the inline mock maker."

dependencies {
testImplementation project(":junit-jupiter")
testImplementation libraries.assertj
testImplementation libraries.junitJupiterApi
testRuntimeOnly libraries.junitJupiterEngine
testRuntimeOnly libraries.junitPlatformLauncher
}

test {
useJUnitPlatform()
}

This file was deleted.

@@ -1,8 +1,7 @@
description = "Tests that require fine tuned parallel settings for JUnit Jupiter (bug #1630)"

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

apply plugin: "java"
description = "Tests that require fine tuned parallel settings for JUnit Jupiter (bug #1630)"

dependencies {
testImplementation libraries.junitJupiterApi
Expand Down
@@ -1,30 +1,15 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${libraries.kotlin.version}"
}
plugins {
id 'org.jetbrains.kotlin.jvm'
}

apply plugin: "org.jetbrains.kotlin.jvm"
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "Kotlin tests for Mockito."

repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}

java {
sourceCompatibility = 11
targetCompatibility = 11
}

tasks.withType(KotlinCompile).configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
Expand Down
9 changes: 2 additions & 7 deletions subprojects/kotlinTest/kotlinTest.gradle
Expand Up @@ -3,17 +3,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'org.jetbrains.kotlin.jvm'
id 'java'
}

description = "Kotlin tests for Mockito."

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

java {
sourceCompatibility = 11
targetCompatibility = 11
}
description = "Kotlin tests for Mockito."

tasks.withType(KotlinCompile).configureEach {
compilerOptions {
Expand Down
10 changes: 3 additions & 7 deletions subprojects/memory-test/memory-test.gradle
@@ -1,18 +1,14 @@
plugins {
id 'java'
}
description = "Test suite memory usage of Mockito"

apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "Test suite memory usage of Mockito"

dependencies {
implementation project.rootProject
testImplementation libraries.junit4
testImplementation libraries.assertj
}

tasks.javadoc.enabled = false

test {
maxHeapSize = "128m"
}
14 changes: 2 additions & 12 deletions subprojects/module-test/module-test.gradle
@@ -1,20 +1,10 @@
plugins {
id 'java'
}
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/java-test.gradle"

description = "Test suite for Java 9 modules with Mockito"

apply from: "$rootDir/gradle/dependencies.gradle"

dependencies {
implementation project.rootProject
testImplementation libraries.junit4
testImplementation libraries.assertj
}

tasks.javadoc.enabled = false

java {
sourceCompatibility = 11
targetCompatibility = 11
}
4 changes: 1 addition & 3 deletions subprojects/osgi-test/osgi-test-bundles.gradle
Expand Up @@ -7,9 +7,7 @@ buildscript {
}
}

apply from: "$rootDir/gradle/dependencies.gradle"

description = "Test bundles for OSGi tests"
// Test bundles for OSGi tests

sourceSets {
testBundle
Expand Down

0 comments on commit a7bc931

Please sign in to comment.