gpt4 book ai didi

java - maven-clean-plugin 不删除文件

转载 作者:行者123 更新时间:2023-12-03 20:33:19 27 4
gpt4 key购买 nike

我有以下 pom.xml,我想在其中删除 generated我把一些 *.java 放在那里后的目录来自 generate-sources 的文件阶段:

    <dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- This plugin generates java files in generated directory -->
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
...
</executions>
</plugin>
<!-- To clean the generated directory in service package -->
<plugin>
<groupId>maven</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>/src/main/java/com/acme/Network/service/generated</directory>
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>**/*.log</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>

我想用 maven clean 删除生成的整个包来自 m2e。但它只删除目标目录,生成的目录保持不变。

我做错了什么?

最佳答案

首先 - 从依赖项中删除 maven-clean-plugin。它是插件,不是依赖。

第二:尝试

<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/src/main/java/com/acme/Network/service/generated</directory>
</fileset>
</filesets>
</configuration>

</plugin>

您的路径以/src 开头 - 它是从根/开始的全局路径。对你来说,根是项目 ${basedir}

第三:生成的源应该按照惯例添加到:

${basedir}/target/generated-sources然后当你运行“干净”时 - 它也会被删除。您可以跳过第二个步骤。

使用helper plugin向项目添加其他源码包(intellij和eclipse应该可以看到):

     <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

更新覆盖 avro-maven-plugin在你的 pom 中:

<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/target/generated-sources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

关于java - maven-clean-plugin 不删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19677201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com