Gradle error when attempting to turn off debug option in java application

project.zip (55.4 KB)

An introductory course at https://dpeuniversity.gradle.com/ outlines how to turn off debug option when compiling a simple java application. I am trying to follow along to get it to work.

Specifically, adding the section

tasks.named<JavaCompile>('compileJava') {
    this.options.isDebug = false
}

to build.gradle file is supposed to get this job done.

When I do this in my simple project, I am getting this error

What went wrong:
A problem occurred evaluating project ‘:app’.

Could not get unknown property ‘named’ for task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.

Could not figure out what I am doing wrong.

Attaching my simple gradle project to this question.

You are mixing Groovy DSL and Kotlin DSL and try to stuff it into a Groovy DSL file, that cannot work.

In Groovy DSL it would be

tasks.named('compileJava') {
   options.debug = false
}

In Kotlin DSL - which I strongly recommend - it would be

tasks.named<JavaCompile>("compileJava") {
    options.isDebug = false
}

or simply

tasks.compileJava {
    options.isDebug = false
}