繁体   English   中英

maven-clean-plugin不删除文件

[英]maven-clean-plugin not delete files

我有以下pom.xml,我想从generate-sources阶段放入一些*.java文件后删除generated目录:

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

我希望通过m2e从maven clean删除生成的整个包。 但它只删除目标目录,生成的目录保持不变。

我究竟做错了什么?

首先 - 从依赖项中删除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开头 - 它是来自root /的全局路径。 对你来说,root是项目$ {basedir}

第三:应按惯例将生成的来源添加到:

${basedir}/target/generated-sources然后当你运行“clean”时 - 它也将被删除。 你可以跳过第二步

使用helper插件将其他源包添加到项目中(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>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM