2014-05-20 93 views
3

我在写一个Jenkins插件,但对Java和Maven都是新手。如何在构建Jenkins插件时获得编译器警告

当我在intelliJ中构建插件时,我得到了所有我期望看到的编译器警告(例如,弃用警告),但我找不到通过命令行进行编译的方式(例如使用mvn HPI:HPI/MVN编译)

我已经尝试添加下列行到一个Maven设置文件的行家编译-插件部但没有效果:

<showDeprecation>true</showDeprecation> 
<showWarnings>true</showWarnings> 

的这个最终目的是在jenkins上编译插件并将警告提供给警告插件。

+0

我正在尝试同样的事情。你有没有成功? – k2col

+0

还没有,但是如果我知道的话,我会确保回复。 – user3658295

回答

2

两个建议你可以试试:

1)添加编译器参数的-Xlint:所有:

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<version>3.0</version> 
<configuration> 
     <source>1.6</source> 
     <target>1.6</target> 
     <compilerArgument>-Xlint:all</compilerArgument> 
     <showWarnings>true</showWarnings> 
     <showDeprecation>true</showDeprecation> 
    </configuration> 
</plugin> 

2)尝试通过命令行传递的参数是这样的:

mvn clean install -Dmaven.compiler.showDeprecation=true 

祝你好运!

0

基于TimHauschildt的答案,我不得不改变我的詹金斯pom.xml文件看起来像这样:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>org.jenkins-ci.plugins</groupId> 
    <artifactId>plugin</artifactId> 
    <version>1.509.4</version> 
    </parent> 

    <groupId>org.jenkins-ci.plugins</groupId> 
    <artifactId>test-plugin</artifactId> 
    <version>1.00</version> 
    <name>Test Plugin</name> 
    <packaging>hpi</packaging> 

    <repositories> 
    <repository> 
     <id>repo.jenkins-ci.org</id> 
     <url>http://repo.jenkins-ci.org/public/</url> 
    </repository> 
    </repositories> 

    <pluginRepositories> 
    <pluginRepository> 
     <id>repo.jenkins-ci.org</id> 
     <url>http://repo.jenkins-ci.org/public/</url> 
    </pluginRepository> 
    </pluginRepositories> 

    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.0</version> 
      <configuration> 
      <source>1.6</source> 
      <target>1.6</target> 
      <compilerArgument>-Xlint:all</compilerArgument> 
      <showWarnings>true</showWarnings> 
      <showDeprecation>true</showDeprecation> 
      </configuration> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 

</project> 

然后跑mvn compile。 之后,Jenkins中的警告插件可以提取警告。

-Dmaven.compiler.showDeprecation=true选项也运行良好,但输出量取决于jenkins/maven默认选择的编译器插件版本。