Skip to content

Move to Gradle conventions plugins #3464

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

Merged
merged 17 commits into from
Oct 16, 2024
Merged
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

- name: 3. Validate Gradle wrapper
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
uses: gradle/wrapper-validation-action@v3.5.0 # https://github.com/gradle/wrapper-validation-action
uses: gradle/actions/wrapper-validation@v4 # https://github.com/gradle/wrapper-validation-action

- name: 4. Build and check reproducibility of artifacts (single job only)
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
Expand All @@ -74,7 +74,6 @@ jobs:
./gradlew
-Pmockito.test.java=${{ matrix.java }}
build
idea
--stacktrace
--scan
env:
Expand Down
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ reduce risk, and improve code health, while paying the maintainers of the exact
## Development

Mockito publishes every change as a `-SNAPSHOT` version to a public Sonatype repository. Roughly once a month, we
publish a new minor or patch version to Maven Central. For release automation we use Shipkit
library (http://shipkit.org), Gradle Nexus [Publish Plugin](https://github.com/gradle-nexus/publish-plugin).
publish a new minor or patch version to Maven Central. For release automation we use
[Shipkit library](http://shipkit.org), [Gradle Nexus Publish Plugin](https://github.com/gradle-nexus/publish-plugin).
Fully automated releases are awesome, and you should do that for your libraries, too!
See the [latest release notes](https://github.com/mockito/mockito/releases/)
and [latest documentation](https://javadoc.io/page/org.mockito/mockito-core/latest/org/mockito/Mockito.html). Docs in
Expand Down Expand Up @@ -64,25 +64,22 @@ Enjoy Mockito!

To build locally:

./gradlew build

To develop in IntelliJ IDEA you can use built-in Gradle import wizard in IDEA. Alternatively generate the importable
IDEA metadata files using:

./gradlew idea

Then, _open_ the generated *.ipr file in IDEA.
```shell
./gradlew build
```
You can open in any IDE that support Gradle, e.g. IntelliJ IDEA, or Fleet.
For Eclipse, one may need to run `./gradlew eclipse` before importing the project.

## How to release new version?

1. Every change on the main development branch is released as `-SNAPSHOT` version to Sonatype snapshot repo
at https://s01.oss.sonatype.org/content/repositories/snapshots/org/mockito/mockito-core.
2. In order to release a non-snapshot version to Maven Central push an annotated tag, for example:
2. To release a non-snapshot version to Maven Central push an annotated tag, for example:

```
git tag -a -m "Release 3.4.5" v3.4.5
git push origin v3.4.5
```
```shell
git tag -a -m "Release 3.4.5" v3.4.5
git push origin v3.4.5
```

3. At the moment, you **may not create releases from GitHub Web UI**. Doing so will make the CI build fail because the
CI creates the changelog and posts to GitHub releases. We'll support this in the future.
36 changes: 3 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {

dependencies {
classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:4.0.1'

classpath "io.github.gradle-nexus:publish-plugin:2.0.0-rc-1"
classpath 'org.shipkit:shipkit-changelog:2.0.1'
Expand All @@ -20,45 +19,16 @@ buildscript {
}

plugins {
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.ben-manes.versions' version '0.51.0'
id("eclipse")
id("com.diffplug.spotless") version "6.25.0"
id("com.github.ben-manes.versions") version "0.51.0"
}

apply from: "$rootDir/gradle/shipkit.gradle"
apply from: "$rootDir/gradle/root/ide.gradle"
apply from: "$rootDir/gradle/license.gradle"

subprojects { proj ->
repositories {
mavenCentral()
google()
}
plugins.withId('java') {
proj.apply from: "$rootDir/gradle/errorprone.gradle"
proj.apply from: "$rootDir/gradle/jfr.gradle"
proj.apply from: "$rootDir/gradle/spotless.gradle"
}
tasks.withType(JavaCompile).configureEach {
//I don't believe those warnings add value given modern IDEs
options.warnings = false
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc).configureEach {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
options.setSource('11')
}

tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
dirMode = Integer.parseInt("0755", 8)
fileMode = Integer.parseInt("0644", 8)
}

apply plugin: 'checkstyle'
checkstyle {
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
}
}
14 changes: 14 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
// doc: https://docs.gradle.org/current/userguide/kotlin_dsl.html
`kotlin-dsl`
}

dependencies {
implementation(libs.gradleplugin.testLogger)
implementation(libs.gradleplugin.animalSniffer)
implementation(libs.gradleplugin.bnd)
implementation(libs.gradleplugin.errorprone)

// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
11 changes: 11 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.kotlin.dsl.the

val Project.libs
get() = the<LibrariesForLibs>()

val Project.sourceSets
get() = the<SourceSetContainer>()
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/MockitoJavadoc.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.gradle.api.provider.Property

interface MockitoJavadocExtension {
val title: Property<String>
val docTitle: Property<String>
}
19 changes: 19 additions & 0 deletions buildSrc/src/main/kotlin/mockito.checkstyle-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.kotlin.dsl.checkstyle
import org.gradle.kotlin.dsl.withType

plugins {
checkstyle
}

checkstyle {
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
}

tasks.withType<Checkstyle>().configureEach {
reports {
xml.required.set(false)
html.required.set(true)
html.stylesheet = resources.text.fromFile("$rootDir/config/checkstyle/checkstyle.xsl")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension

plugins {
java // for sourceSets
id("ru.vyarus.animalsniffer")
}


val main: SourceSet by sourceSets.getting
configure<AnimalSnifferExtension> {
sourceSets = listOf(main)
annotation = "org.mockito.internal.SuppressSignatureCheck"

// See please https://github.com/mojohaus/animal-sniffer/issues/172
ignore(
"java.lang.instrument.Instrumentation",
"java.lang.invoke.MethodHandle",
"java.lang.invoke.MethodHandles\$Lookup",
"java.lang.StackWalker",
"java.lang.StackWalker\$StackFrame",
"java.lang.StackWalker\$Option",
)
}

dependencies {
// Equivalent to "net.sf.androidscents.signature:android-api-level-26:8.0.0_r2@signature"
signature(variantOf(libs.animalSniffer.android.apiLevel26) { artifactType("signature") })
signature(variantOf(libs.animalSniffer.java) { artifactType("signature") })
}

34 changes: 34 additions & 0 deletions buildSrc/src/main/kotlin/mockito.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension

// only apply to Java projects
// i.e., do nothing when applied to Android projects
plugins.withType(JavaPlugin::class) {
val javaReleaseVersion = 11

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.toVersion(javaReleaseVersion)
targetCompatibility = JavaVersion.toVersion(javaReleaseVersion)
}

tasks {
withType<JavaCompile>().configureEach {
// I don't believe those warnings add value given modern IDEs
options.isWarnings = false
options.encoding = "UTF-8"
}

withType<Javadoc>().configureEach {
options {
encoding = "UTF-8"
source = javaReleaseVersion.toString()

if (this is StandardJavadocDocletOptions) {
addStringOption("Xdoclint:none", "-quiet")
addStringOption("charSet", "UTF-8")
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
`java-library`
id("mockito.java-conventions")
id("mockito.test-conventions")
id("mockito.test-retry-conventions")
id("mockito.test-launcher-conventions")
id("net.ltgt.errorprone")
}

if (!project.name.startsWith("mockito-")) {
throw GradleException("Published project module should be prefixed with `mockito-` : ${project.projectDir})")
}

repositories {
mavenCentral()
google()
}

dependencies {
errorprone(libs.errorprone)
}

tasks {
withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
// dirMode = Integer.parseInt("0755", 8)
dirPermissions {
unix("rwxr-xr-x") // 0755
}
// fileMode = Integer.parseInt("0644", 8)
filePermissions {
unix("rw-r--r--") // 0644
}
}
}
67 changes: 67 additions & 0 deletions buildSrc/src/main/kotlin/mockito.javadoc-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import org.gradle.api.tasks.javadoc.Javadoc

plugins {
java
}

val mockitoJavadocExtension = project.extensions.create<MockitoJavadocExtension>("mockitoJavadoc").apply {
title.convention(project.name)
docTitle.convention("<h1>${project.name}</h1>")
}

val javadocConfigDir = "$rootDir/config/javadoc"

tasks.named<Javadoc>("javadoc") {
inputs.dir(javadocConfigDir)
description = "Creates javadoc html for ${project.name}."

// For more details on the format
// see https://docs.oracle.com/en/java/javase/21/javadoc/javadoc.html

source = project.sourceSets["main"].allJava

options {
title = mockitoJavadocExtension.title.get()
destinationDirectory = project.layout.buildDirectory.dir("javadoc").get().asFile
encoding = "UTF-8"

if (this is StandardJavadocDocletOptions) {
addBooleanOption("-allow-script-in-comments", true)
addFileOption("-add-stylesheet", file("$javadocConfigDir/resources/mockito-theme.css"))
addStringOption("Xwerror", "-quiet")
charSet = "UTF-8"
docEncoding = "UTF-8"
docTitle = mockitoJavadocExtension.docTitle.get()

bottom(
"""
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/obsidian.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
""".trimIndent().replace("\r|\n|[ ]{8}".toRegex(), "")
)

group("Main package", "org.mockito")
links("https://junit.org/junit4/javadoc/${project.libs.versions.junit4.get()}/")
linksOffline(
"https://docs.oracle.com/en/java/javase/11/docs/api/",
"$javadocConfigDir/jdk-package-list"
)

isSplitIndex = true
isUse = true
windowTitle = mockitoJavadocExtension.title.get()

addBooleanOption("html5", true)
}
memberLevel = JavadocMemberLevel.PROTECTED
outputLevel = JavadocOutputLevel.QUIET

doLast {
copy {
from("$javadocConfigDir/resources")
into(project.layout.buildDirectory.dir("javadoc"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
base
id("mockito.java-library-conventions")
id("mockito.osgi-conventions")
id("mockito.publication-conventions")
id("mockito.checkstyle-conventions")
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/mockito.osgi-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("biz.aQute.bnd.builder")
}
Loading