Maven Clean 不会清理旧类并生成新类

标签 maven pom.xml

我在 Maven 中遇到奇怪的问题。完成 Maven 全新安装后,当我通过 7 zip 打开 jar 文件时,在 jar 文件内,我可以看到两个类文件,而不是一个,它们是一个旧的类文件和一个新编译的类文件,其当前时间戳如附图所示。

我尝试过故障排除,例如清除目标文件夹并尝试重新编译,修复 Maven 编译器 3.1 的已知问题(useIncrementalCompilation -yes (true))。

但是它仍然是一样的,我已经没有想法了。我也是 Java 新手,它对我来说非常重要。非常感谢您的任何帮助和想法。

Classes

聚甲醛

<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>Some Content here</groupId>
  <artifactId>alert</artifactId>
  <version>1</version>
  <dependencies>
  	
	<dependency>
		<groupId>Some Content Here</groupId>
		<artifactId>processing</artifactId>
		<version>2.2</version>
	</dependency>

	<dependency>
		<groupId>javax.mail</groupId>
		<artifactId>javax.mail-api</artifactId>
		<version>1.5.6</version>
	</dependency>
	<dependency>
		<groupId>javax.activation</groupId>
		<artifactId>activation</artifactId>
		<version>1.1.1</version>
	</dependency>
	<dependency>
	    <groupId>com.sun.mail</groupId>
	    <artifactId>javax.mail</artifactId>
	    <version>1.5.6</version>
	</dependency>
	<dependency>
	    <groupId>sax</groupId>
	    <artifactId>sax</artifactId>
	    <version>2.0.1</version>
	</dependency>
	<dependency>
	    <groupId>org.apache.commons</groupId>
	    <artifactId>commons-lang3</artifactId>
	    <version>3.6</version>
	</dependency>
		
	<dependency>
	    <groupId>javax.servlet</groupId>
	    <artifactId>servlet-api</artifactId>
	    <version>2.5</version>
	</dependency>
	<dependency>
		<groupId>javax</groupId>
		<artifactId>javaee-api</artifactId>
    	<version>6.0</version>
	</dependency>
  </dependencies>
  <build>
	  	<sourceDirectory>src/main/java</sourceDirectory>	
		<resources>
			<resource>
	        	<directory>src/main/resources</directory>
	    	</resource>
	    </resources>
	    <plugins>
			<plugin>
		        <artifactId>maven-assembly-plugin</artifactId>
		        <executions>
		          <execution>
		            <phase>package</phase>
		            <goals>
		              <goal>single</goal>
		            </goals>
		          </execution>
		        </executions>
		        <configuration>
		          <descriptorRefs>
		            <descriptorRef>jar-with-dependencies</descriptorRef>
		          </descriptorRefs>
		        </configuration>
	      </plugin>
	    </plugins>
	</build>
</project>

日志

[INFO] javax/transaction/UserTransaction.class already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] META-INF/maven/javax.javaee.api/ already added, skipping
[INFO] META-INF/maven/javax.javaee.api/javaee.api-compact/ already added, skipping
[INFO] META-INF/maven/javax.javaee.api/javaee.api-compact/pom.xml already added, skipping
[INFO] META-INF/maven/javax.javaee.api/javaee.api-compact/pom.properties already added, skipping
[INFO] DBConnect.properties already added, skipping
[INFO] EmailSetting.properties already added, skipping
[INFO] SourceConnect.properties already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ alert ---
[INFO] Installing C:\AA\alert\target\alert-1.jar to C:\Users\AA\.m2\repository\com\bb\automation\alert\1\alert-1.jar
[INFO] Installing C:\AA\alert\pom.xml to C:\Users\AA\.m2\repository\com\bb\automation\alert\1\alert-1.pom
[INFO] Installing C:\AA\alert\target\alert-1-jar-with-dependencies.jar to C:\Users\AA\.m2\repository\com\bb\automation\alert\1\alert-1-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.371 s
[INFO] Finished at: 2018-03-13T10:47:07+08:00
[INFO] Final Memory: 39M/404M
[INFO] ------------------------------------------------------------------------

有效的 POM

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Some Content Here</groupId>
  <artifactId>alert</artifactId>
  <version>1</version>
  <dependencies>
    <dependency>
      <groupId>Some Content Here</groupId>
      <artifactId>processing</artifactId>
      <version>2.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>javax.mail-api</artifactId>
      <version>1.5.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.activation</groupId>
      <artifactId>activation</artifactId>
      <version>1.1.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.mail</groupId>
      <artifactId>javax.mail</artifactId>
      <version>1.5.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>sax</groupId>
      <artifactId>sax</artifactId>
      <version>2.0.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>6.0</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>C:\AA\alert\src\main\java</sourceDirectory>
    <scriptSourceDirectory>C:\AA\alert\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\AA\alert\src\test\java</testSourceDirectory>
    <outputDirectory>C:\AA\alert\target\classes</outputDirectory>
    <testOutputDirectory>C:\AA\alert\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\AA\alert\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\AA\alert\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\AA\alert\target</directory>
    <finalName>alert-1</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.3</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\AA\alert\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\AA\alert\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>C:\AA\alert\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>C:\AA\alert\target\site</outputDirectory>
  </reporting>
</project>

最佳答案

我已通过清除项目的本地存储库依赖项解决了该问题。根据插件文档,

插件的默认行为是首先解析整个依赖关系树,然后从本地存储库中删除内容,然后从远程存储库中重新解析依赖关系。

现在运行良好!!干杯!!

https://snag.gy/qvzoAL.jpg

https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html

mvn dependency:purge-local-repository

来源:

来自其他社区的一个叫 Martijn 的人建议我删除 .m2 存储库,但由于我害怕删除 .m2 存储库,所以在阅读多个在线资源后,我使用该插件从项目的本地存储库中删除依赖项。

https://snag.gy/FcdBqz.jpg

关于Maven Clean 不会清理旧类并生成新类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49247753/

相关文章:

java - 无法将 war 复制到 Google 存储桶

java - Maven 的 WAR 依赖

java - 如何在 pom 中设置不编译测试?

java - Linux 中的 Oozie 4.0.1 构建错误

java - Maven 站点插件 : Define url in parent without adding subdirectories

java - eclipse 。手动运行测试并使用 "maven install"后的不同行为

maven - 当我有多个用于该目标的配置时,如何在 Maven 插件中使用特定配置运行特定目标

Maven — 从 pom 中的 settings.xml 读取凭据

apache-flex - flex 4.6 pom 文件依赖没有解决

java - 在 Spring 中覆盖库版本