mCs
mCs

Reputation: 177

maven-clean-plugin not delete files

I have the following pom.xml where I want to delete the generated directory after I put there some *.java files from generate-sources phase:

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

I want to have the entire package generated deleted with maven clean from m2e. But it just deletes ONLY the target dir and the generated dir stays untouched.

What am I doing wrong?

Upvotes: 3

Views: 9690

Answers (1)

Andrzej Jozwik
Andrzej Jozwik

Reputation: 14649

First - remove maven-clean-plugin from dependencies. It is plugin, not dependency.

Second: try

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

            </plugin>

Your path start with /src - it is global path from root / . For you the root is project ${basedir}

Third: Generated sources should be added by convention to:

${basedir}/target/generated-sources Then when you run "clean" - it will be removed also. And you can skip second step.

Use helper plugin to add other source package to the project (intellij and eclipse should see it):

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

Update Override avro-maven-plugin in your 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>

Upvotes: 11

Related Questions