Skip to content

Commit

Permalink
Convert all samples to Groovy DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Aug 31, 2023
1 parent afd04d5 commit 25f44ed
Show file tree
Hide file tree
Showing 402 changed files with 737 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

dependencies {
Expand Down
7 changes: 7 additions & 0 deletions 02_The_Build_Files/my-project/data-model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("java-library")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
7 changes: 0 additions & 7 deletions 02_The_Build_Files/my-project/data-model/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
`kotlin-dsl`
id("groovy-gradle-plugin")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id("application")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

tasks.named("test") {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ plugins {
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

tasks.test {
tasks.named("test") {
useJUnitPlatform()
}

Expand Down

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions 04_Tasks/my-build-logic/java-plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("groovy-gradle-plugin")
}
3 changes: 0 additions & 3 deletions 04_Tasks/my-build-logic/java-plugins/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("application")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("java-library")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions 05_Lifecycle_Tasks/my-build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tasks.register("checkAll") {
dependsOn(subprojects.collect { ":${it.name}:check" })
}
3 changes: 0 additions & 3 deletions 05_Lifecycle_Tasks/my-build-logic/build.gradle.kts

This file was deleted.

3 changes: 3 additions & 0 deletions 05_Lifecycle_Tasks/my-build-logic/java-plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("groovy-gradle-plugin")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id("application")
}

val myBuildGroup = "my project build"
def myBuildGroup = "my project build"

tasks.named("run") {
group = myBuildGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ plugins {
id("checkstyle")
}

val myBuildGroup = "my project build"
tasks.named<TaskReportTask>("tasks") {
def myBuildGroup = "my project build"
tasks.named("tasks") {
displayGroup = myBuildGroup
}

tasks.register<TaskReportTask>("tasksAll") {
tasks.register("tasksAll", TaskReportTask) {
group = myBuildGroup
description = "Show additional tasks."
setShowDetail(true)
}

tasks.build {
tasks.named("build") {
group = myBuildGroup
}
tasks.check {
tasks.named("check") {
group = myBuildGroup
description = "Runs checks (including tests)."
}
Expand Down Expand Up @@ -49,10 +49,10 @@ tasks.register("lifecycleTasks") {
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

tasks.test {
tasks.named("test") {
useJUnitPlatform()
testLogging.showStandardStreams = true
}
Expand Down
3 changes: 3 additions & 0 deletions 05_Lifecycle_Tasks/my-other-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tasks.register("checkAll") {
dependsOn(subprojects.collect { ":${it.name}:check" })
}
3 changes: 0 additions & 3 deletions 05_Lifecycle_Tasks/my-other-project/build.gradle.kts

This file was deleted.

17 changes: 17 additions & 0 deletions 05_Lifecycle_Tasks/my-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def globalBuildGroup = "My global build"
def ciBuildGroup = "My CI build"

tasks.named("tasks") {
displayGroup = globalBuildGroup
}

tasks.register("qualityCheckAll") {
group = globalBuildGroup
dependsOn(subprojects.collect { ":${it.name}:qualityCheck" })
}

tasks.register("checkAll") {
group = ciBuildGroup
dependsOn(subprojects.collect { ":${it.name}:check" })
dependsOn(gradle.includedBuilds.collect { it.task(":checkAll") })
}
17 changes: 0 additions & 17 deletions 05_Lifecycle_Tasks/my-project/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("groovy-gradle-plugin")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins {
id("my-java-base")
}

val packageApp = tasks.register<Zip>("packageApp") {
def packageApp = tasks.register("packageApp", Zip) {
from(layout.projectDirectory.file("run.sh"))
from(tasks.jar) {
from(tasks.named("jar")) {
into("libs")
}
from(configurations.runtimeClasspath) {
Expand All @@ -15,7 +15,7 @@ val packageApp = tasks.register<Zip>("packageApp") {
archiveFileName.set("myApplication.zip")
}

tasks.build {
tasks.named("build") {
dependsOn(packageApp)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("java")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("groovy-gradle-plugin")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ plugins {
id("my-java-base")
}

val myApp = extensions.create<MyAppExtension>("myApp")
def myApp = extensions.create("myApp", MyAppExtension)

val generateStartScript = tasks.register<GenerateStartScript>("generateStartScript") {
def generateStartScript = tasks.register("generateStartScript", GenerateStartScript) {
mainClass.convention(myApp.mainClass)
scriptFile.set(layout.buildDirectory.file("run.sh"))
}

val packageApp = tasks.register<Zip>("packageApp") {
def packageApp = tasks.register("packageApp", Zip) {
from(generateStartScript)
from(tasks.jar) {
into("libs")
Expand All @@ -25,7 +25,7 @@ val packageApp = tasks.register<Zip>("packageApp") {
archiveFileName.set("myApplication.zip")
}

tasks.build {
tasks.named("build") {
dependsOn(packageApp)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("java")
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package myproject.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import java.nio.file.Files
import static java.nio.file.attribute.PosixFilePermission.*

@CacheableTask
abstract class GenerateStartScript extends DefaultTask {

@Input
abstract Property<String> getMainClass()

@OutputFile
abstract RegularFileProperty getScriptFile()

@TaskAction
def generate() {
def main = mainClass.get() // String
def out = scriptFile.get().asFile // java.io.File
def script = "java -cp 'libs/*' $main"

out.text = script
Files.setPosixFilePermissions(out.toPath(), [
OWNER_READ, OWNER_WRITE, OWNER_EXECUTE,
GROUP_READ, GROUP_EXECUTE,
OTHERS_EXECUTE, OTHERS_READ
] as Set)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package myproject.tasks
import org.gradle.api.provider.Property

interface MyAppExtension {
val mainClass: Property<String>
Property<String> getMainClass()
}

This file was deleted.

Loading

0 comments on commit 25f44ed

Please sign in to comment.