Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to compiler and javadoc in gradle

I am trying to provide Gradle as an alternative build system on an existing project. That project makes use of sun.misc.Unsafe which leads to warnings like this one:

warning: Unsafe is internal proprietary API and may be removed in a future release
import sun.misc.Unsafe; 

To suppress this warning -XDignore.symbol.file is passed as an argument to javac and javadoc in the current ant script.

In order to suppress these warnings in Gradle I had to resort to what I feel are 'dirty' hacks that I am not too comfortable with.

apply plugin: 'java'

compileJava {
    // I only managed to get this working when I forked 
    // and passed 'javac' as an executable
    options.compilerArgs << '-XDignore.symbol.file'
    options.fork = true
    options.forkOptions.executable = 'javac'
}


javadoc {
    // These get ignored
    // options.addStringOption('XDignore.symbol.file', null)
    // options.addStringOption('XDignore.symbol.file')

    // This one fails the build - I am assuming it's trying to parse ''
    // options.addStringOption('XDignore.symbol.file')

    // This works, but it's an ugly hack
    options.addStringOption('XDignore.symbol.file', '-quiet')
}

Surely there must be a more elegant way that I don't know to achieve this.

Here ( https://gist.github.com/3772416 ) is a more complete example with an accompanying ant script and a sample class that causes the problem.

Thanks

I am running Gradle 1.1

------------------------------------------------------------
Gradle 1.1
------------------------------------------------------------

Gradle build time: Tuesday, 31 July 2012 13:24:32 o'clock UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0_07 (Oracle Corporation 23.3-b01)
OS: Linux 3.2.0-30-generic amd64

It seems that this is a reasonable worakround at the moment for suppressing these particular warnings. See - http://forums.gradle.org/gradle/topics/passing_arguments_to_compiler_and_javadoc?rfm=1

like image 760
Dalibor Novak Avatar asked Sep 23 '12 18:09

Dalibor Novak


People also ask

How do you pass arguments in gradle?

If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin's run task, then you can pass your parameters through the --args=... command line option. For example gradle run --args="foo --bar=true" .

What is Javadoc in gradle?

Javadoc. Generates HTML API documentation for Java classes. If you create your own Javadoc tasks remember to specify the 'source' property! Without source the Javadoc task will not create any documentation. Example: plugins { id 'java' } task myJavadocs(type: Javadoc) { source = sourceSets.main.allJava }


1 Answers

Regarding Javadoc, the following might work:

javadoc.options.jflags "-XDignore.symbol.file"

Regarding Java compilation, it would be good to know if options.fork = true and options.forkOptions.executable = 'javac' are still required with recent Gradle versions (e.g. 1.2). If yes, please file a problem at http://forums.gradle.org.

like image 54
Peter Niederwieser Avatar answered Sep 28 '22 03:09

Peter Niederwieser