maven-antrun-plugin打war包不能替换成功

880 阅读1分钟

profile控制

  • 完成了以下事情

    • 通过变量定义profile里头的属性

    • 先添加版本之后

    • 拷贝不通的资源文件到指定目录

    • 注意:prepare-package

      <profile>
                  <id>setup</id>
                  <properties>
                      <forest-type>vtradex</forest-type>
                  </properties>
                  <build>
                      <plugins>
                          <plugin>
                              <groupId>com.google.code.maven-replacer-plugin</groupId>
                              <artifactId>replacer</artifactId>
                              <version>1.5.3</version>
                              <executions>
                                  <!-- 打包前进行替换 -->
                                  <execution>
                                      <phase>prepare-package</phase>
                                      <goals>
                                          <goal>replace</goal>
                                      </goals>
                                  </execution>
                              </executions>
                              <configuration>
                                  <!-- 自动识别到项目target文件夹 -->
                                  <basedir>${project.build.directory}</basedir>
                                  <!-- 替换的文件所在目录规则 -->
                                  <includes>
                                      <include>${project.build.finalName}/static/${forest-type}/index.html</include>
                                      <!--                        <include>${project.build.finalName}/WEB-INF/**/*.html</include>-->
                                  </includes>
      
                                  <replacements>
                                      <!-- 更改规则,在css/js文件末尾追加?v=时间戳,反斜杠表示字符转义 -->
                                      <replacement>
                                          <token>\.css\"</token>
                                          <value>.css?v=${project.version}-${maven.build.timestamp}\"</value>
                                      </replacement>
                                      <replacement>
                                          <token>\.css\'</token>
                                          <value>.css?v=${project.version}-${maven.build.timestamp}\'</value>
                                      </replacement>
                                      <replacement>
                                          <token>\.js\"</token>
                                          <value>.js?v=${project.version}-${maven.build.timestamp}\"</value>
                                      </replacement>
                                      <replacement>
                                          <token>\.js\'</token>
                                          <value>.js?v=${project.version}-${maven.build.timestamp}\'</value>
                                      </replacement>
      
                                  </replacements>
                              </configuration>
                          </plugin>
                          <plugin>
                              <groupId>org.apache.maven.plugins</groupId>
                              <artifactId>maven-antrun-plugin</artifactId>
                              <version>1.1</version>
                              <executions>
                                  <execution>
                                       <!--如果这里是package,则不能完成覆盖 -->
                                      <phase>prepare-package</phase>
                                      <goals>
                                          <goal>run</goal>
                                      </goals>
                                      <configuration>
                                          <tasks>
                                              <echo>Using ${project.build.directory}/${project.name}</echo>
                                              <copy todir="${project.build.directory}\${project.name}\" verbose="true" overwrite="true">
                                                  <fileset dir="${project.build.directory}\${project.name}\static\${forest-type}">
                                                      <include name="*.html" />
                                                      <include name="*.js" />
                                                  </fileset>
                                              </copy>
                                          </tasks>
                                      </configuration>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>
              </profile>