This Gradle plugin applies common configuration that we use in our JVM projects at Kontur. It aids to avoid boilerplate in build scripts.
The plugin consists of several configuration blocks (called presets)
which are mainly triggered when some relevant plugin is applied (e.g. java or maven-publish).
plugins {
id 'ru.kontur.kinfra.presets' version '<version>'
}Currently, the plugin requires Gradle version 8.0.
By default, Gradle caches dependencies that are changing (snapshots)
or have dynamic versions (e.g. 1.+) for 24 hours.
Such caching is disabled.
When there are no repositories configured in the project at the time the plugin applied, following default repositories are added:
-
Local Maven cache (
mavenLocal) -
Sonatype's Maven Central (
mavenCentral)
This behavior can be customized in two ways:
-
Add additional repositories
To use other repositories in your project just declare them in
repositories { }block. -
Use other repositories instead of default ones
To prevent use of these default repositories you need to add other repositories before application of the plugin.
This can be done in init script:
allprojects { repostitories { maven { url = "repo.mycompany.com" } } }Or in
settings.gradle:gradle.projectsLoaded { gradle.allprojects { repositories { maven { url = "repo.mycompany.com" } } } }
For now, default Java version in our projects is 17. It is set via java.toolchain.languageVersion.
When a test fails, its exception's stack trace is being logged to console. It helps to investigate failure on CI faster.
We use JUnit 5 for in-project (unit and some integration) tests.
Dependency on a recent JUnit release is automatically added by the plugin. To override it, add dependency on JUnit BOM of desired version manually:
dependncies {
testImplementation platform("org.junit:junit-bom:<version>")
}The following options are added to Kotlin compiler command line by the plugin:
-
-java-parameters: generate metadata for Java reflection on method parameters. -
-Xjsr305=strict: use JSR-305 nullability annotations. (details) -
-Xjvm-default=all: compile non-abstract interface methods as Java default methods. -
-opt-in=kotlin.RequiresOptIn: allow usage of@OptInand@RequiresOptInannotations.
Dependency on Kotlin stdlib is automatically added to implementation configuration.
Its version is the same as Kotlin plugin's one.
The plugin creates a MavenPublication named maven and adds a project component to it:
-
In a
java-libraryproject thejavacomponent is being added. -
In a
java-platformproject thejavaPlatformcomponent is being added.
Usually our projects that are being published are either of these.
Publication's artifactId is changed to project's archivesBaseName instead of project's name.
Configuration of the POM can be accessed via pom { } block in the project, just as in MavenPublication.
Also, plugin creates a task named install as an alias for publishToMavenLocal.
A task named sourcesJar is created in the project using Gradle's built-in feature.
Obliviously it packages project's main sources into a JAR with sources classifier.