Skip to content

Commit

Permalink
Question about how to use a common versions object
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Sep 8, 2021
1 parent aa35e6a commit 8177332
Show file tree
Hide file tree
Showing 27 changed files with 279 additions and 729 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
@@ -0,0 +1,11 @@
# Set default behavior to automatically normalize line endings.
* text=auto

# Force batch scripts to always use CRLF line endings so that if a repo is accessed
# in Windows via a file share from Linux, the scripts will work.
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

# Force bash scripts to always use LF line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf
35 changes: 3 additions & 32 deletions README.md
@@ -1,34 +1,5 @@
This is a simple project where I try to understand how to use gradle and `buildSrc` for dependency management. It is also used to ask the gradle folks for help.
# Helpme

All the "requests for help" in this project can be found by searching for "HELPME".
How to use the object `buildSrc/src/main/kotlin/land/tbp/wwsc/Versions.kt` inside `buildSrc/build.gradle.kts`?

The initial project sources taken from gradle documentation itself: https://docs.gradle.org/current/samples/sample_convention_plugins.html. Press the "Kotlin DSL" button at the top.

Unfortunately those are rather lackluster as they don't help with setting up a proper application which uses multiple technologies. That's why I created this project which tries to set up a spring boot + kotlin project.


# Problems (HELPME)

This is a blocker for me right now, so it gets its own readme section.

## How can i find the name of a "plugin dependency"?

- `id("org.springframework.boot")` is found at https://plugins.gradle.org/plugin/org.springframework.boot and i assume the dependency is `implementation("org.springframework.boot:spring-boot-gradle-plugin:2.5.4")`
- `kotlin("jvm")` is found at https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm and i assume the dependency is `implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")`
-`kotlin("plugin.spring")` is found at https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.spring, however i have no idea what i should add as dependency.

The problem here (imo) is that the website https://plugins.gradle.org/ does not show the "plugin dependency name" itself.
It has 2 examples:

- `Using the plugins DSL`
- `Using legacy plugin application`

However, there is no `Using buildSrc plugin dependency`. Can that be added as well?



# How to run:

```
gradle clean check jacocoTestReport bootJar
```
I want to do this because I want to store the versions of my libraries and plugins in one central place.
55 changes: 30 additions & 25 deletions buildSrc/build.gradle.kts
@@ -1,36 +1,41 @@
// HELPME: how can i not duplicate V?
object V {
const val springBootVersion = "2.5.3"
const val kotlinVersion = "1.5.10"
}


// TODO: HELPME
// How to use the versions from the central location `land.tbp.wwsc.Versions`?
// Using the following imports does not work as the imports aren't found.
//import land.tbp.wwsc.Versions.gradleTaskinfoVersion
//import land.tbp.wwsc.Versions.kotlinLibraryVersion
//import land.tbp.wwsc.Versions.ktlintGradleVersion
//import land.tbp.wwsc.Versions.sonarqubeVersion
//import land.tbp.wwsc.Versions.springBootVersion
/////////////////

// So, I have to duplicate the imports code, which is bad.
val kotlinLibraryVersion = "1.5.10"
val springBootVersion = "2.5.3"
val ktlintGradleVersion = "10.1.0"
val sonarqubeVersion = "3.3"
val gradleTaskinfoVersion = "1.3.0"

/*
How to test?
Comment the val calls above and uncomment the imports. gradle will complain that it doesn't know what to import.
*/
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
gradlePluginPortal()
}

dependencies {
implementation("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.6.2")
testImplementation("junit:junit:4.13")

// used for kotlin with spring project
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${V.kotlinVersion}")
implementation("org.springframework.boot:spring-boot-gradle-plugin:${V.springBootVersion}")

// HELPME: what is the name of the plugin containing kotlin spring ( kotlin("plugin.spring") )?
// From https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.spring, i expect it to be
// implementation("org.jetbrains.kotlin:kotlin-allopen:1.5.10")
// but that makes no sense.
// @gradle documentation folks: Where can i find the name of the plugins??


implementation("gradle.plugin.org.barfuin.gradle.taskinfo:gradle-taskinfo:1.3.0")
implementation("org.jlleitschuh.gradle:ktlint-gradle:10.1.0")
implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinLibraryVersion")
implementation("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")

implementation("org.jetbrains.kotlin:kotlin-allopen:$kotlinLibraryVersion")
implementation("org.jetbrains.kotlin:kotlin-noarg:$kotlinLibraryVersion")

implementation("gradle.plugin.org.barfuin.gradle.taskinfo:gradle-taskinfo:$gradleTaskinfoVersion")
implementation("org.jlleitschuh.gradle:ktlint-gradle:$ktlintGradleVersion")
implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:$sonarqubeVersion")
}
26 changes: 0 additions & 26 deletions buildSrc/src/main/java/com/example/CheckstyleUtil.java

This file was deleted.

38 changes: 0 additions & 38 deletions buildSrc/src/main/java/com/example/ReadmeVerificationTask.java

This file was deleted.

37 changes: 37 additions & 0 deletions buildSrc/src/main/kotlin/land/tbp/wwsc/Versions.kt
@@ -0,0 +1,37 @@
package land.tbp.wwsc

import org.gradle.api.JavaVersion

object Versions {
val javaVersion = JavaVersion.VERSION_11
const val kotlinLanguageApiVersion = "1.5"

const val kotlinLibraryVersion = "1.5.10"

const val springBootVersion = "2.5.3"
const val springCloudVersion = "2020.0.3"
const val springCloudGcpPubsubVersion = "2.0.3"

const val oracleJdbc = "19.3.0.0"

const val jacksonVersion = "2.12.4"

const val keycloakVersion = "13.0.1"
const val openApiVersion = "1.5.10"
const val logstashLogbackEncoderVersion = "6.6"

const val h2Version = "1.4.200"
const val prometheusVersion = "1.7.2"

const val kittinunfResultVersion = "3.1.0"

const val springMockkVersion = "3.0.1"
const val mockKVersion = "1.12.0"
const val assertJVersion = "3.20.2"
const val awaitilityVersion = "4.1.0"
const val mockitoCore = "2.8.9"

const val ktlintGradleVersion = "10.1.0"
const val sonarqubeVersion = "3.3"
const val gradleTaskinfoVersion = "1.3.0"
}
@@ -1,39 +1,52 @@
// HELPME: how can i not duplicate V?
object V {
const val springBootVersion = "2.5.3"
const val kotlinVersion = "1.5.10"
val javaVersion = JavaVersion.VERSION_11
}


package land.tbp.wwsc
import land.tbp.wwsc.Versions.springBootVersion
import land.tbp.wwsc.Versions.h2Version
import land.tbp.wwsc.Versions.openApiVersion
import land.tbp.wwsc.Versions.springMockkVersion
import land.tbp.wwsc.Versions.assertJVersion
import land.tbp.wwsc.Versions.awaitilityVersion

plugins {
kotlin("jvm")
id("org.springframework.boot")
// HELPME: what is the name of this plugin? how to import it? see the question inside the dependencies
// kotlin("plugin.spring")


kotlin("plugin.spring")
id("org.barfuin.gradle.taskinfo")
id("org.jlleitschuh.gradle.ktlint")
id("org.sonarqube")
jacoco
application
}

repositories {
mavenLocal()
mavenCentral()
}


dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

implementation(platform("org.springframework.boot:spring-boot-dependencies:${V.springBootVersion}"))

implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.integration:spring-integration-core")
developmentOnly("org.springframework.boot:spring-boot-devtools:${V.springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))

implementation("com.h2database:h2:$h2Version")

implementation("org.springdoc:springdoc-openapi-kotlin:$openApiVersion")
implementation("org.springdoc:springdoc-openapi-ui:$openApiVersion")


testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.springframework.boot:spring-boot-starter-test")

testImplementation("com.ninja-squad:springmockk:$springMockkVersion")
testImplementation("org.assertj:assertj-core:$assertJVersion")

testImplementation("org.awaitility:awaitility-kotlin:$awaitilityVersion")


configurations.all {
Expand All @@ -45,51 +58,24 @@ dependencies {
}
}


repositories {
mavenCentral()
}


java.sourceCompatibility = Versions.javaVersion
java.targetCompatibility = Versions.javaVersion

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs += listOf("-Xjsr305=strict")
jvmTarget = V.javaVersion.majorVersion
languageVersion = "1.5"
apiVersion = "1.5"
}
}

withType<Test> {
useJUnitPlatform()
}

sonarqube {
properties {
property("sonar.projectName", "test")
property("sonar.projectKey", "test")
property("sonar.kotlin.coveragePlugin", "jacoco")
property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/test/jacocoTestReport.xml")
}
}

test {
finalizedBy(jacocoTestReport) // report is always generated after tests run
}

jacocoTestReport {
dependsOn(test)

reports {
reports.html.required.set(true)
reports.xml.required.set(true)
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
@Suppress("SuspiciousCollectionReassignment")
freeCompilerArgs += listOf("-Xjsr305=strict")
jvmTarget = Versions.javaVersion.majorVersion
languageVersion = Versions.kotlinLanguageApiVersion
apiVersion = Versions.kotlinLanguageApiVersion
}
}
}


configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
verbose.set(true)
disabledRules.set(setOf("no-wildcard-imports"))
Expand Down
28 changes: 0 additions & 28 deletions buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kts

This file was deleted.

0 comments on commit 8177332

Please sign in to comment.