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

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

问题描述

我试图将Gradle作为现有项目的替代构建系统。该项目使用 sun.misc.Unsafe ,导致如下警告:

 警告:不安全是内部专有API,可能会在未来版本中删除
import sun.misc.Unsafe;

禁止此警告 -XDignore.symbol.file 作为参数传递给当前ant脚本中的javac和javadoc。



为了在Gradle中抑制这些警告,我必须诉诸于我的感受'肮脏'的黑客,我不太舒服。

  apply插件:'java'

compileJava {
//我只在设置
//并将'javac'作为可执行文件传递给
options.compilerArgs<< '-XDignore.symbol.file'
options.fork = true
options.forkOptions.executable ='javac'
}


javadoc {
//这些被忽略
// options.addStringOption('XDignore.symbol.file',null)
// options.addStringOption('XDignore.symbol.file')

//这个失败了构建 - 我假设它试图解析''
// options.addStringOption('XDignore.symbol.file')

// This工程,但它是一个丑陋的黑客
options.addStringOption('XDignore.symbol.file','-quiet')
}

当然,必须有一种更优雅的方式,我不知道要达到这个目的。



这里( https://gist.github.com/3772416 )是一个更完整的示例,其中包含一个伴随的ant脚本和导致该问题的示例类。



谢谢

我正在运行Gradle 1.1

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

Gradle编译时间:2012年7月31日星期二13:24:32上午UTC
Groovy:1.8.6
Ant:Apache Ant(TM)1.8.4版2012年5月22日编译
Ivy:2.2.0
JVM:1.7.0_07(Oracle Corporation 23.3-b01)
操作系统:Linux 3.2.0-30-generic amd64

似乎这是一个合理的时间来抑制这些特定的警告。请参阅 - http://forums.gradle.org/gradle/topics/passing_arguments_to_compiler_and_javadoc?rfm=1

解决方案

关于Javadoc,以下方法可能有效:

<$ p $ javadoc.options.jflags-XDignore.symbol.file

关于Java编译,最好知道 options.fork = true options.forkOptions.executable ='javac'(例如1.2)。如果是,请在 http://forums.gradle.org 上提出问题。


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

解决方案

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.

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

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