Open rogerxu opened 1 year ago
A multi-project build must have a settings.gradle
file in the root project of the multi-project hierarchy.
settings.gradle.kts
rootProject.name = "basic"
println("This is executed during the initialization phase.")
Build Script Basics (gradle.org)
Building Java Applications Sample (gradle.org)
Building Java & JVM projects (gradle.org)
build.gradle.kts
plugins {
`java-library`
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
version = "1.2.1"
The Java Library Plugin also integrates the above tasks into the standard Base Plugin lifecycle tasks:
jar
is attached to assemble
test
is attached to check
build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("org.hibernate:hibernate-core:3.6.7.Final")
}
compileOnly
— for dependencies that are necessary to compile your production code but shouldn’t be part of the runtime classpathimplementation
(supersedes compile
) — used for compilation and runtimeruntimeOnly
(supersedes runtime
) — only used at runtime, not for compilationtestCompileOnly
— same as compileOnly
except it’s for the teststestImplementation
— test equivalent of implementation
testRuntimeOnly
— test equivalent of runtimeOnly
Structuring and Building a Software Component with Gradle
Sharing Build Logic between Subprojects (gradle.org)
We recommend putting source code and tests for the convention plugins in the special buildSrc
directory in the root directory of the project.
Using buildSrc to organize build logic
Sharing build logic between subprojects Sample (gradle.org)
Structuring Large Projects (gradle.org)
The JaCoCo Plugin (gradle.org)
build.gradle.kts
plugins {
java,
jacoco
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(true)
}
}
tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
subprojects
in the root project, legacy approach
subprojects {
apply(plugin = "java")
apply(plugin = "jacoco")
val jacocoTestReport by tasks.existing(JacocoReport::class) {
reports {
xml.required.set(true)
csv.required.set(true)
}
}
val test by tasks.existing {
finalizedBy(jacocoTestReport)
}
}
Run command
$ ./gradlew check
SonarScanner for Gradle (sonarqube.org)
Gradle - Plugin: org.sonarqube
build.gradle.kts
plugins {
id("org.sonarqube") version "3.5.0.2730"
}
sonarqube {
properties {
property("sonar.projectName", "Project Name")
property("sonar.projectDescription", "Project description")
property("sonar.links.ci", "https://cirrus-ci.com/github/SonarSource/sonar-kotlin")
property("sonar.links.scm", "https://github.com/SonarSource/sonar-kotlin")
property("sonar.links.issue", "https://jira.sonarsource.com/browse/SONARKT")
}
}
subproject/build.gradle.kts
plugins {
java
jacoco
}
sonarqube {
properties {
property("sonar.coverage.exclusions", "**/*")
}
}
Trigger sonar scan
$ ./gradlew check sonar
Gradle User Manual