Recompile with -Xlint parameters

I’m having these warnings when building:

Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

I just want to know how to recompile with these parameters (-Xlint:deprecation and -Xlint:unchecked), even if it is warning I don’t want to supress it, but get the details.

Thanks in advance.

You need to configure your JavaCompile tasks with those extra arguments. If you want this for all JavaCompile tasks rather than just particular ones, you can do this:

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:unchecked'
    options.deprecation = true
}

The CompileOptions on the JavaCompile tasks has a deprecation property you can configure directly and not worry about actual command line argument, but you can add both -Xlint:deprecation and -Xlint:unchecked as compilerArgs, if you want.

2 Likes

Awesome, it works.

Thank you.

1 Like

Hello, I’m having this exact same issue. Where do I insert the line of code that you shared? Should I be looking for a JavaComplie file? Or is this something you add to gradle-wrapper.properties or some other file related to the program installation.

For some extra info, I’m using gradle to build the newest version of Picard, but I keep getting the same warnings above. The build finishes “successfully” but when I run the tests, I get a failed test.

@sjfleck The code snippet is typically added to a build.gradle file in your project. This can be the project root build.gradle file or build.gradle file of one of your project’s modules.
You can add it to the root level inside that file - it does not need to be nested inside another code element.

is there a way to set it on command line without changing build.gradle.kts?

You could write an init script that sets the parameter and specify that init script via -I parameter when invoking Gradle or putting it to your <GRADLE_USER_HOME>/init.d/.

Example content of a verbose-compile.init.gradle.kts:

allprojects {
    tasks.withType<JavaCompile>().configureEach {
        options.compilerArgs.add("-Xlint:unchecked")
        options.isDeprecation = true
    }
}
1 Like

i would like know exacly in what part of the documentacion have you found informaticion about configurate tasks.whithType?

There’s a number of examples of withType throughout the documentation. For example, Building Java Projects shows using it for a number of different task types. However, using withType without configureEach as was the case when this thread was started is also outdated with Task Configuration Avoidance. The withType itself is a more generic concept that is part of DomainObjectCollection<T>, which the TaskContainer referred to as tasks implements, as do many other types in Gradle.

1 Like