【问题标题】:Maven: Cleaning gwt-unitCache directoryMaven:清理 gwt-unitCache 目录
【发布时间】:2020-10-30 20:38:26
【问题描述】:

我有一个专家问题。

我有一个 GWT 项目,它生成一个临时目录 gwt-unitCache 文件夹。我想在构建过程结束时将其删除。

我有这个插件配置:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main</directory>
                <includes>
                    <directory>gwt-unitCache/**</directory>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
        </execution>
    </executions>
</plugin>

这通过删除 src/main 下自动生成的 gwt-unitCache 文件夹来完成它的工作。但是,它也删除了包含类和战争文件的目标文件夹。

我不想删除目标文件,因此我通过删除部分来修改配置:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main</directory>
                <includes>
                    <directory>gwt-unitCache/**</directory>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>
    <executions>
        <execution>
            <id>gwt-unitCache</id>
            <phase>install</phase>
        </execution>
    </executions>
</plugin>

但这一次它不再起作用了。 gwt-unitCache 不会被删除。看起来插件是在构建过程的开始而不是结束时运行的。

我不擅长 Maven。有人可以帮忙吗?我该如何配置它:

  1. gwt-unitCache 在构建过程结束时被移除。
  2. 目标文件夹未删除。

我使用命令: maven 全新安装

构建它。

非常感谢。

【问题讨论】:

    标签: java gwt maven


    【解决方案1】:

    未经测试,但maven-clean-plugin 公开了一个excludeDefaultDirectories,可以帮助完成这项工作。比如:

    <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <filesets>
                <fileset>
                    <directory>src/main</directory>
                    <includes>
                        <directory>gwt-unitCache/**</directory>
                    </includes>
                    <followSymlinks>false</followSymlinks>
                </fileset>
            </filesets>
            <excludeDefaultDirectories>true</excludeDefaultDirectories>
        </configuration>
        <executions>
            <execution>
                <id>gwt-unitCache</id>
                <phase>install</phase>
                <goals>
                    <goal>clean</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    顺便说一句,我不明白你为什么需要清除这个目录,你不能在你的 SCM 中忽略它吗?

    【讨论】:

    • 非常感谢。问题解决了!是的,我可以简单地将其从 SCM 中排除。只是想学习如何使用这个插件。非常感谢。
    【解决方案2】:

    RC 我使用这个变体在干净阶段仍然照常工作。

    <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>gwt-unitCache</id>
                <phase>install</phase>
                <goals>
                    <goal>clean</goal>
                </goals>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${project.build.directory}/${project.build.finalName}/c</directory>
                            <includes>
                                <directory>gwt-unitCache/**</directory>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                    <excludeDefaultDirectories>true</excludeDefaultDirectories>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 配置单元缓存目录的创建位置不是更方便吗?
    • 我没有找到方法,你呢?
    • IIRC 您将使用gwt.persistentunitcachedir 系统属性。
    【解决方案3】:

    因为它出现在评论中:您可以像这样更改缓存目录的位置:

    <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>gwt-maven-plugin</artifactId>
    
     <configuration>
       <persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
     </configuration>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2011-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多