将参数传递给 gradle 中的编译器和 javadoc [英] Passing arguments to compiler and javadoc in gradle

查看:34
本文介绍了将参数传递给 gradle 中的编译器和 javadoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提供 Gradle 作为现有项目的替代构建系统.该项目利用了 sun.misc.Unsafe 这会导致如下警告:

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; 

为了抑制此警告,-XDignore.symbol.file 作为参数传递给当前 ant 脚本中的 javac 和 javadoc.

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

为了在 Gradle 中抑制这些警告,我不得不求助于我觉得不太舒服的肮脏"黑客.

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.

这里 ( https://gist.github.com/3772416 ) 是一个更完整的示例,附带一个 ant 脚本和导致问题的示例类.

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

谢谢

我正在运行 Gradle 1.1

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

这似乎是目前抑制这些特定警告的合理方法.请参阅 - http://forums.gradle.org/gradle/topics/passing_arguments_to_compiler_and_javadoc?rfm=1

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

推荐答案

关于 Javadoc,以下可能有效:

Regarding Javadoc, the following might work:

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

关于 Java 编译,最好知道最近的 Gradle 版本是否仍然需要 options.fork = trueoptions.forkOptions.executable = 'javac'(例如 1.2).如果是,请在 http://forums.gradle.org 提出问题.

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.

这篇关于将参数传递给 gradle 中的编译器和 javadoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆