Trouble with -Xlint:all and maven

后端 未结 1 1330
庸人自扰
庸人自扰 2021-02-10 10:01

I\'m trying to get maven to output lint level warnings. I\'ve created a small test program that should generate a warning about using a static method from a non-static context,

相关标签:
1条回答
  • 2021-02-10 10:40

    This "works for me" with your sources.

    <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.buck</groupId>
      <artifactId>mavenproject3</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>jar</packaging>
    
      <name>mavenproject3</name>
      <url>http://maven.apache.org</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <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>
        </plugins>
      </build>
    </project>
    

    I imagine that the reason your commented out attempt with

                    <compilerArguments>
                        <Xlint:all />
                    </compilerArguments>
    

    is failing because of the XML namespace "Xlint" that the "all" tag would fall into, which means that the entire tag "Xlint:all" probably wasn't even seen by the maven configuration parser (being in a different namespace and all).

    By the way, the relevant lines of output

    Compiling 1 source file to C:\Users\edwbuck\Documents\NetBeansProjects\mavenproject3\target\classes
    bootstrap class path not set in conjunction with -source 1.6
    com/buck/mavenproject3/App.java:[12,35] static method should be qualified by type name, java.lang.String, instead of by an expression
    

    and my environment

    Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600)
    Maven home: C:\Program Files\NetBeans 7.2.1\java\maven
    Java version: 1.7.0_07, vendor: Oracle Corporation
    Java home: C:\Program Files (x86)\Java\jdk1.7.0_07\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
    

    Perhaps you stepped on a platform specific bug?

    0 讨论(0)
提交回复
热议问题