How to get compiler warnings when building a Jenki

2019-06-28 03:57发布

I'm writing a Jenkins plugin but am new to both Java and Maven.

When I build the plugin in intelliJ I get all of the compiler warnings I expect to see (deprecation warnings for example) but I can't find a way to compile via the command line that will show these (eg with mvn hpi:hpi / mvn compile)

I've tried adding the following lines to the maven-compiler-plugin section of a Maven settings file but to no avail:

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

The ultimate aim of this is to compile the plugin on jenkins and feed the warnings into the warnings plugin.

2条回答
Summer. ? 凉城
2楼-- · 2019-06-28 04:32

Two suggestions you can try:

1) Add the compiler-argument -Xlint:all:

<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.) Try passing the arguments via command line like this:

mvn clean install -Dmaven.compiler.showDeprecation=true

Good Luck!

查看更多
你好瞎i
3楼-- · 2019-06-28 04:32

Based on TimHauschildt's answer, I had to modify my jenkins pom.xml file to look like this:

<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>

Then ran mvn compile. After that the warnings plugin in Jenkins could pick up the warnings.

The -Dmaven.compiler.showDeprecation=true option also worked well, but the amount of output varied depending on what version of the compiler plugin jenkins/maven chose by default.

查看更多
登录 后发表回答