Use configuration avoidance APIs in Gradle plugin's docs

Closes gh-30056
pull/30505/head
Andy Wilkinson 3 years ago
parent 58e2adb895
commit e7566e968e

@ -7,7 +7,7 @@ plugins {
apply(plugin = "io.spring.dependency-management") apply(plugin = "io.spring.dependency-management")
// end::apply[] // end::apply[]
task("verify") { tasks.register("verify") {
doLast { doLast {
project.plugins.getPlugin(JavaPlugin::class) project.plugins.getPlugin(JavaPlugin::class)
project.plugins.getPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin::class) project.plugins.getPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin::class)

@ -26,7 +26,7 @@ the<DependencyManagementExtension>().apply {
} }
} }
task("slf4jVersion") { tasks.register("slf4jVersion") {
doLast { doLast {
println(project.the<DependencyManagementExtension>().managedVersions["org.slf4j:slf4j-api"]) println(project.the<DependencyManagementExtension>().managedVersions["org.slf4j:slf4j-api"])
} }

@ -3,18 +3,18 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::builder[] // tag::builder[]
bootBuildImage { tasks.named("bootBuildImage") {
builder = "mine/java-cnb-builder" builder = "mine/java-cnb-builder"
runImage = "mine/java-cnb-run" runImage = "mine/java-cnb-run"
} }
// end::builder[] // end::builder[]
task bootBuildImageBuilder { tasks.register("bootBuildImageBuilder") {
doFirst { doFirst {
println("builder=${tasks.bootBuildImage.builder}") println("builder=${tasks.bootBuildImage.builder}")
println("runImage=${tasks.bootBuildImage.runImage}") println("runImage=${tasks.bootBuildImage.runImage}")

@ -6,12 +6,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::builder[] // tag::builder[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
builder = "mine/java-cnb-builder" builder = "mine/java-cnb-builder"
runImage = "mine/java-cnb-run" runImage = "mine/java-cnb-run"
} }

@ -4,12 +4,12 @@ plugins {
} }
// tag::buildpacks[] // tag::buildpacks[]
bootBuildImage { tasks.named("bootBuildImage") {
buildpacks = ["file:///path/to/example-buildpack.tgz", "urn:cnb:builder:paketo-buildpacks/java"] buildpacks = ["file:///path/to/example-buildpack.tgz", "urn:cnb:builder:paketo-buildpacks/java"]
} }
// end::buildpacks[] // end::buildpacks[]
task bootBuildImageBuildpacks { tasks.register("bootBuildImageBuildpacks") {
doFirst { doFirst {
bootBuildImage.buildpacks.each { reference -> println "$reference" } bootBuildImage.buildpacks.each { reference -> println "$reference" }
} }

@ -6,7 +6,7 @@ plugins {
} }
// tag::buildpacks[] // tag::buildpacks[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
buildpacks = listOf("file:///path/to/example-buildpack.tgz", "urn:cnb:builder:paketo-buildpacks/java") buildpacks = listOf("file:///path/to/example-buildpack.tgz", "urn:cnb:builder:paketo-buildpacks/java")
} }
// end::buildpacks[] // end::buildpacks[]

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::docker-auth-token[] // tag::docker-auth-token[]
bootBuildImage { tasks.named("bootBuildImage") {
docker { docker {
builderRegistry { builderRegistry {
token = "9cbaf023786cd7..." token = "9cbaf023786cd7..."
@ -17,7 +17,7 @@ bootBuildImage {
} }
// end::docker-auth-token[] // end::docker-auth-token[]
task bootBuildImageDocker { tasks.register("bootBuildImageDocker") {
doFirst { doFirst {
println("token=${tasks.bootBuildImage.docker.builderRegistry.token}") println("token=${tasks.bootBuildImage.docker.builderRegistry.token}")
} }

@ -6,12 +6,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::docker-auth-token[] // tag::docker-auth-token[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
docker { docker {
builderRegistry { builderRegistry {
token = "9cbaf023786cd7..." token = "9cbaf023786cd7..."

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::docker-auth-user[] // tag::docker-auth-user[]
bootBuildImage { tasks.named("bootBuildImage") {
docker { docker {
builderRegistry { builderRegistry {
username = "user" username = "user"
@ -20,7 +20,7 @@ bootBuildImage {
} }
// end::docker-auth-user[] // end::docker-auth-user[]
task bootBuildImageDocker { tasks.register("bootBuildImageDocker") {
doFirst { doFirst {
println("username=${tasks.bootBuildImage.docker.builderRegistry.username}") println("username=${tasks.bootBuildImage.docker.builderRegistry.username}")
println("password=${tasks.bootBuildImage.docker.builderRegistry.password}") println("password=${tasks.bootBuildImage.docker.builderRegistry.password}")

@ -6,12 +6,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::docker-auth-user[] // tag::docker-auth-user[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
docker { docker {
builderRegistry { builderRegistry {
username = "user" username = "user"

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::docker-host[] // tag::docker-host[]
bootBuildImage { tasks.named("bootBuildImage") {
docker { docker {
host = "tcp://192.168.99.100:2376" host = "tcp://192.168.99.100:2376"
tlsVerify = true tlsVerify = true
@ -17,7 +17,7 @@ bootBuildImage {
} }
// end::docker-host[] // end::docker-host[]
task bootBuildImageDocker { tasks.register("bootBuildImageDocker") {
doFirst { doFirst {
println("host=${tasks.bootBuildImage.docker.host}") println("host=${tasks.bootBuildImage.docker.host}")
println("tlsVerify=${tasks.bootBuildImage.docker.tlsVerify}") println("tlsVerify=${tasks.bootBuildImage.docker.tlsVerify}")

@ -6,12 +6,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::docker-host[] // tag::docker-host[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
docker { docker {
host = "tcp://192.168.99.100:2376" host = "tcp://192.168.99.100:2376"
isTlsVerify = true isTlsVerify = true

@ -4,7 +4,7 @@ plugins {
} }
// tag::env[] // tag::env[]
bootBuildImage { tasks.named("bootBuildImage") {
environment = [ environment = [
"HTTP_PROXY" : "http://proxy.example.com", "HTTP_PROXY" : "http://proxy.example.com",
"HTTPS_PROXY": "https://proxy.example.com" "HTTPS_PROXY": "https://proxy.example.com"
@ -12,7 +12,7 @@ bootBuildImage {
} }
// end::env[] // end::env[]
task bootBuildImageEnvironment { tasks.register("bootBuildImageEnvironment") {
doFirst { doFirst {
bootBuildImage.environment.each { name, value -> println "$name=$value" } bootBuildImage.environment.each { name, value -> println "$name=$value" }
} }

@ -6,7 +6,7 @@ plugins {
} }
// tag::env[] // tag::env[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
environment = mapOf("HTTP_PROXY" to "http://proxy.example.com", environment = mapOf("HTTP_PROXY" to "http://proxy.example.com",
"HTTPS_PROXY" to "https://proxy.example.com") "HTTPS_PROXY" to "https://proxy.example.com")
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::env-runtime[] // tag::env-runtime[]
bootBuildImage { tasks.named("bootBuildImage") {
environment = [ environment = [
"BPE_DELIM_JAVA_TOOL_OPTIONS" : " ", "BPE_DELIM_JAVA_TOOL_OPTIONS" : " ",
"BPE_APPEND_JAVA_TOOL_OPTIONS" : "-XX:+HeapDumpOnOutOfMemoryError" "BPE_APPEND_JAVA_TOOL_OPTIONS" : "-XX:+HeapDumpOnOutOfMemoryError"
@ -16,7 +16,7 @@ bootBuildImage {
} }
// end::env-runtime[] // end::env-runtime[]
task bootBuildImageEnvironment { tasks.register("bootBuildImageEnvironment") {
doFirst { doFirst {
bootBuildImage.environment.each { name, value -> println "$name=$value" } bootBuildImage.environment.each { name, value -> println "$name=$value" }
} }

@ -6,7 +6,7 @@ plugins {
} }
// tag::env-runtime[] // tag::env-runtime[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
environment = mapOf( environment = mapOf(
"BPE_DELIM_JAVA_TOOL_OPTIONS" to " ", "BPE_DELIM_JAVA_TOOL_OPTIONS" to " ",
"BPE_APPEND_JAVA_TOOL_OPTIONS" to "-XX:+HeapDumpOnOutOfMemoryError" "BPE_APPEND_JAVA_TOOL_OPTIONS" to "-XX:+HeapDumpOnOutOfMemoryError"

@ -4,12 +4,12 @@ plugins {
} }
// tag::env[] // tag::env[]
bootBuildImage { tasks.named("bootBuildImage") {
environment = ["BP_JVM_VERSION" : "8.*"] environment = ["BP_JVM_VERSION" : "8.*"]
} }
// end::env[] // end::env[]
task bootBuildImageEnvironment { tasks.register("bootBuildImageEnvironment") {
doFirst { doFirst {
bootBuildImage.environment.each { name, value -> println "$name=$value" } bootBuildImage.environment.each { name, value -> println "$name=$value" }
} }

@ -6,7 +6,7 @@ plugins {
} }
// tag::env[] // tag::env[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
environment = mapOf("BP_JVM_VERSION" to "8.*") environment = mapOf("BP_JVM_VERSION" to "8.*")
} }
// end::env[] // end::env[]

@ -4,13 +4,13 @@ plugins {
} }
// tag::image-name[] // tag::image-name[]
bootBuildImage { tasks.named("bootBuildImage") {
imageName = "example.com/library/${project.name}" imageName = "example.com/library/${project.name}"
} }
// end::image-name[] // end::image-name[]
task bootBuildImageName { tasks.register("bootBuildImageName") {
doFirst { doFirst {
println(tasks.bootBuildImage.imageName) println(tasks.bootBuildImage.imageName)
} }
} }

@ -6,13 +6,13 @@ plugins {
} }
// tag::image-name[] // tag::image-name[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
imageName = "example.com/library/${project.name}" imageName = "example.com/library/${project.name}"
} }
// end::image-name[] // end::image-name[]
tasks.register("bootBuildImageName") { tasks.register("bootBuildImageName") {
doFirst { doFirst {
println(tasks.getByName<BootBuildImage>("bootBuildImage").imageName) println(tasks.getByName<BootBuildImage>("bootBuildImage").imageName)
} }
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::publish[] // tag::publish[]
bootBuildImage { tasks.named("bootBuildImage") {
imageName = "docker.example.com/library/${project.name}" imageName = "docker.example.com/library/${project.name}"
publish = true publish = true
docker { docker {
@ -22,8 +22,8 @@ bootBuildImage {
} }
// end::publish[] // end::publish[]
task bootBuildImagePublish { tasks.register("bootBuildImagePublish") {
doFirst { doFirst {
println(tasks.bootBuildImage.publish) println(tasks.bootBuildImage.publish)
} }
} }

@ -6,12 +6,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::publish[] // tag::publish[]
tasks.getByName<BootBuildImage>("bootBuildImage") { tasks.named<BootBuildImage>("bootBuildImage") {
imageName = "docker.example.com/library/${project.name}" imageName = "docker.example.com/library/${project.name}"
isPublish = true isPublish = true
docker { docker {
@ -26,7 +26,7 @@ tasks.getByName<BootBuildImage>("bootBuildImage") {
// end::publish[] // end::publish[]
tasks.register("bootBuildImagePublish") { tasks.register("bootBuildImagePublish") {
doFirst { doFirst {
println(tasks.getByName<BootBuildImage>("bootBuildImage").isPublish) println(tasks.getByName<BootBuildImage>("bootBuildImage").isPublish)
} }
} }

@ -4,15 +4,15 @@ plugins {
} }
// tag::classifiers[] // tag::classifiers[]
bootJar { tasks.named("bootJar") {
archiveClassifier = 'boot' archiveClassifier = 'boot'
} }
jar { tasks.named("jar") {
archiveClassifier = '' archiveClassifier = ''
} }
// end::classifiers[] // end::classifiers[]
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.Application' mainClass = 'com.example.Application'
} }

@ -6,15 +6,15 @@ plugins {
} }
// tag::classifiers[] // tag::classifiers[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
archiveClassifier.set("boot") archiveClassifier.set("boot")
} }
tasks.getByName<Jar>("jar") { tasks.named<Jar>("jar") {
archiveClassifier.set("") archiveClassifier.set("")
} }
// end::classifiers[] // end::classifiers[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.Application") mainClass.set("com.example.Application")
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::custom-launch-script[] // tag::custom-launch-script[]
bootJar { tasks.named("bootJar") {
launchScript { launchScript {
script = file('src/custom.script') script = file('src/custom.script')
} }

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::custom-launch-script[] // tag::custom-launch-script[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
launchScript { launchScript {
script = file("src/custom.script") script = file("src/custom.script")
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::include-launch-script[] // tag::include-launch-script[]
bootJar { tasks.named("bootJar") {
launchScript() launchScript()
} }
// end::include-launch-script[] // end::include-launch-script[]

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::include-launch-script[] // tag::include-launch-script[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
launchScript() launchScript()
} }
// end::include-launch-script[] // end::include-launch-script[]

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::launch-script-properties[] // tag::launch-script-properties[]
bootJar { tasks.named("bootJar") {
launchScript { launchScript {
properties 'logFilename': 'example-app.log' properties 'logFilename': 'example-app.log'
} }

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::launch-script-properties[] // tag::launch-script-properties[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
launchScript { launchScript {
properties(mapOf("logFilename" to "example-app.log")) properties(mapOf("logFilename" to "example-app.log"))
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::layered[] // tag::layered[]
bootJar { tasks.named("bootJar") {
layered { layered {
application { application {
intoLayer("spring-boot-loader") { intoLayer("spring-boot-loader") {

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::layered[] // tag::layered[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
layered { layered {
application { application {
intoLayer("spring-boot-loader") { intoLayer("spring-boot-loader") {

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::layered[] // tag::layered[]
bootJar { tasks.named("bootJar") {
layered { layered {
enabled = false enabled = false
} }

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::layered[] // tag::layered[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
layered { layered {
isEnabled = false isEnabled = false
} }

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::layered[] // tag::layered[]
bootJar { tasks.named("bootJar") {
layered { layered {
includeLayerTools = false includeLayerTools = false
} }

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::layered[] // tag::layered[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
layered { layered {
isIncludeLayerTools = false isIncludeLayerTools = false
} }

@ -4,7 +4,7 @@ plugins {
} }
// tag::main-class[] // tag::main-class[]
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// end::main-class[] // end::main-class[]

@ -6,7 +6,7 @@ plugins {
} }
// tag::main-class[] // tag::main-class[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// end::main-class[] // end::main-class[]

@ -4,7 +4,7 @@ plugins {
} }
// tag::main-class[] // tag::main-class[]
bootJar { tasks.named("bootJar") {
manifest { manifest {
attributes 'Start-Class': 'com.example.ExampleApplication' attributes 'Start-Class': 'com.example.ExampleApplication'
} }

@ -6,7 +6,7 @@ plugins {
} }
// tag::main-class[] // tag::main-class[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
manifest { manifest {
attributes("Start-Class" to "com.example.ExampleApplication") attributes("Start-Class" to "com.example.ExampleApplication")
} }

@ -11,12 +11,12 @@ dependencies {
runtimeOnly('org.jruby:jruby-complete:1.7.25') runtimeOnly('org.jruby:jruby-complete:1.7.25')
} }
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::requires-unpack[] // tag::requires-unpack[]
bootJar { tasks.named("bootJar") {
requiresUnpack '**/jruby-complete-*.jar' requiresUnpack '**/jruby-complete-*.jar'
} }
// end::requires-unpack[] // end::requires-unpack[]

@ -13,12 +13,12 @@ dependencies {
runtimeOnly("org.jruby:jruby-complete:1.7.25") runtimeOnly("org.jruby:jruby-complete:1.7.25")
} }
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::requires-unpack[] // tag::requires-unpack[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
requiresUnpack("**/jruby-complete-*.jar") requiresUnpack("**/jruby-complete-*.jar")
} }
// end::requires-unpack[] // end::requires-unpack[]

@ -3,7 +3,7 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootWar { tasks.named("bootWar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
@ -12,7 +12,7 @@ dependencies {
} }
// tag::include-devtools[] // tag::include-devtools[]
bootWar { tasks.named("bootWar") {
classpath configurations.developmentOnly classpath configurations.developmentOnly
} }
// end::include-devtools[] // end::include-devtools[]

@ -5,7 +5,7 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootWar>("bootWar") { tasks.named<BootWar>("bootWar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
@ -14,7 +14,7 @@ dependencies {
} }
// tag::include-devtools[] // tag::include-devtools[]
tasks.getByName<BootWar>("bootWar") { tasks.named<BootWar>("bootWar") {
classpath(configurations["developmentOnly"]) classpath(configurations["developmentOnly"])
} }
// end::include-devtools[] // end::include-devtools[]

@ -3,12 +3,12 @@ plugins {
id 'org.springframework.boot' version '{gradle-project-version}' id 'org.springframework.boot' version '{gradle-project-version}'
} }
bootWar { tasks.named("bootWar") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// tag::properties-launcher[] // tag::properties-launcher[]
bootWar { tasks.named("bootWar") {
manifest { manifest {
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher' attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
} }

@ -5,12 +5,12 @@ plugins {
id("org.springframework.boot") version "{gradle-project-version}" id("org.springframework.boot") version "{gradle-project-version}"
} }
tasks.getByName<BootWar>("bootWar") { tasks.named<BootWar>("bootWar") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// tag::properties-launcher[] // tag::properties-launcher[]
tasks.getByName<BootWar>("bootWar") { tasks.named<BootWar>("bootWar") {
manifest { manifest {
attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher") attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
} }

@ -4,11 +4,11 @@ plugins {
} }
// tag::disable-jar[] // tag::disable-jar[]
jar { tasks.named("jar") {
enabled = false enabled = false
} }
// end::disable-jar[] // end::disable-jar[]
bootJar { tasks.named("bootJar") {
mainClass = 'com.example.Application' mainClass = 'com.example.Application'
} }

@ -6,11 +6,11 @@ plugins {
} }
// tag::disable-jar[] // tag::disable-jar[]
tasks.getByName<Jar>("jar") { tasks.named<Jar>("jar") {
enabled = false enabled = false
} }
// end::disable-jar[] // end::disable-jar[]
tasks.getByName<BootJar>("bootJar") { tasks.named<BootJar>("bootJar") {
mainClass.set("com.example.Application") mainClass.set("com.example.Application")
} }

@ -8,7 +8,7 @@ plugins {
publishing { publishing {
publications { publications {
bootJava(MavenPublication) { bootJava(MavenPublication) {
artifact bootJar artifact tasks.named("bootJar")
} }
} }
repositories { repositories {
@ -19,7 +19,7 @@ publishing {
} }
// end::publishing[] // end::publishing[]
task publishingConfiguration { tasks.register("publishingConfiguration") {
doLast { doLast {
println publishing.publications.bootJava println publishing.publications.bootJava
println publishing.repositories.maven.url println publishing.repositories.maven.url

@ -8,7 +8,7 @@ plugins {
publishing { publishing {
publications { publications {
create<MavenPublication>("bootJava") { create<MavenPublication>("bootJava") {
artifact(tasks.getByName("bootJar")) artifact(tasks.named("bootJar"))
} }
} }
repositories { repositories {
@ -19,7 +19,7 @@ publishing {
} }
// end::publishing[] // end::publishing[]
task("publishingConfiguration") { tasks.register("publishingConfiguration") {
doLast { doLast {
println(publishing.publications["bootJava"]) println(publishing.publications["bootJava"])
println(publishing.repositories.getByName<MavenArtifactRepository>("maven").url) println(publishing.repositories.getByName<MavenArtifactRepository>("maven").url)

@ -5,7 +5,7 @@ plugins {
} }
// tag::upload[] // tag::upload[]
uploadBootArchives { tasks.named("uploadBootArchives") {
repositories { repositories {
mavenDeployer { mavenDeployer {
repository url: 'https://repo.example.com' repository url: 'https://repo.example.com'
@ -14,7 +14,7 @@ uploadBootArchives {
} }
// end::upload[] // end::upload[]
task deployerRepository { tasks.register("deployerRepository") {
doLast { doLast {
println uploadBootArchives.repositories.mavenDeployer.repository.url println uploadBootArchives.repositories.mavenDeployer.repository.url
} }

@ -5,7 +5,7 @@ plugins {
} }
// tag::upload[] // tag::upload[]
tasks.getByName<Upload>("uploadBootArchives") { tasks.named<Upload>("uploadBootArchives") {
repositories.withGroovyBuilder { repositories.withGroovyBuilder {
"mavenDeployer" { "mavenDeployer" {
"repository"("url" to "https://repo.example.com") "repository"("url" to "https://repo.example.com")
@ -14,13 +14,13 @@ tasks.getByName<Upload>("uploadBootArchives") {
} }
// end::upload[] // end::upload[]
val url = tasks.getByName<Upload>("uploadBootArchives") tasks.register("deployerRepository") {
.repositories
.withGroovyBuilder { getProperty("mavenDeployer") }
.withGroovyBuilder { getProperty("repository") }
.withGroovyBuilder { getProperty("url") }
task("deployerRepository") {
doLast { doLast {
val url = tasks.getByName<Upload>("uploadBootArchives")
.repositories
.withGroovyBuilder { getProperty("mavenDeployer") }
.withGroovyBuilder { getProperty("repository") }
.withGroovyBuilder { getProperty("url") }
println(url) println(url)
} }
} }

@ -4,12 +4,12 @@ plugins {
} }
// tag::launch[] // tag::launch[]
bootRun { tasks.named("bootRun") {
optimizedLaunch = false optimizedLaunch = false
} }
// end::launch[] // end::launch[]
task optimizedLaunch { tasks.register("optimizedLaunch") {
doLast { doLast {
println bootRun.optimizedLaunch println bootRun.optimizedLaunch
} }

@ -6,12 +6,12 @@ plugins {
} }
// tag::launch[] // tag::launch[]
tasks.getByName<BootRun>("bootRun") { tasks.named<BootRun>("bootRun") {
isOptimizedLaunch = false isOptimizedLaunch = false
} }
// end::launch[] // end::launch[]
task("optimizedLaunch") { tasks.register("optimizedLaunch") {
doLast { doLast {
println(tasks.getByName<BootRun>("bootRun").isOptimizedLaunch) println(tasks.getByName<BootRun>("bootRun").isOptimizedLaunch)
} }

@ -4,12 +4,12 @@ plugins {
} }
// tag::main[] // tag::main[]
bootRun { tasks.named("bootRun") {
mainClass = 'com.example.ExampleApplication' mainClass = 'com.example.ExampleApplication'
} }
// end::main[] // end::main[]
task configuredMainClass { tasks.register("configuredMainClass") {
doLast { doLast {
println bootRun.mainClass println bootRun.mainClass
} }

@ -6,12 +6,12 @@ plugins {
} }
// tag::main[] // tag::main[]
tasks.getByName<BootRun>("bootRun") { tasks.named<BootRun>("bootRun") {
mainClass.set("com.example.ExampleApplication") mainClass.set("com.example.ExampleApplication")
} }
// end::main[] // end::main[]
task("configuredMainClass") { tasks.register("configuredMainClass") {
doLast { doLast {
println(tasks.getByName<BootRun>("bootRun").mainClass) println(tasks.getByName<BootRun>("bootRun").mainClass)
} }

@ -4,12 +4,12 @@ plugins {
} }
// tag::source-resources[] // tag::source-resources[]
bootRun { tasks.named("bootRun") {
sourceResources sourceSets.main sourceResources sourceSets.main
} }
// end::source-resources[] // end::source-resources[]
task configuredClasspath { tasks.register("configuredClasspath") {
doLast { doLast {
println bootRun.classpath.files println bootRun.classpath.files
} }

@ -6,12 +6,12 @@ plugins {
} }
// tag::source-resources[] // tag::source-resources[]
tasks.getByName<BootRun>("bootRun") { tasks.named<BootRun>("bootRun") {
sourceResources(sourceSets["main"]) sourceResources(sourceSets["main"])
} }
// end::source-resources[] // end::source-resources[]
task("configuredClasspath") { tasks.register("configuredClasspath") {
doLast { doLast {
println(tasks.getByName<BootRun>("bootRun").classpath.files) println(tasks.getByName<BootRun>("bootRun").classpath.files)
} }

@ -4,12 +4,12 @@ plugins {
} }
// tag::system-property[] // tag::system-property[]
bootRun { tasks.named("bootRun") {
systemProperty 'com.example.property', findProperty('example') ?: 'default' systemProperty 'com.example.property', findProperty('example') ?: 'default'
} }
// end::system-property[] // end::system-property[]
task configuredSystemProperties { tasks.register("configuredSystemProperties") {
doLast { doLast {
bootRun.systemProperties.each { k, v -> bootRun.systemProperties.each { k, v ->
println "$k = $v" println "$k = $v"

@ -6,14 +6,14 @@ plugins {
} }
// tag::system-property[] // tag::system-property[]
tasks.getByName<BootRun>("bootRun") { tasks.named<BootRun>("bootRun") {
systemProperty("com.example.property", findProperty("example") ?: "default") systemProperty("com.example.property", findProperty("example") ?: "default")
} }
// end::system-property[] // end::system-property[]
task("configuredSystemProperties") { tasks.register("configuredSystemProperties") {
doLast { doLast {
tasks.getByName<BootRun>("bootRun").systemProperties.forEach { k, v -> tasks.getByName<BootRun>("bootRun").systemProperties.forEach { k, v ->
println("$k = $v") println("$k = $v")
} }
} }

Loading…
Cancel
Save