使用minify-maven-plugin缩小前端

qum*_*uma 4 java minify maven multi-module maven-reactor

我正在使用maven插件minify-maven-plugin来缩小我的前端项目.当我将dos框移到前端项目并执行mvn clean install时,这工作正常,但是当我mvn clean install在我的reactor项目中的主pom中执行时,我得到以下异常:

无法执行目标com.samaxes.maven:minify-maven-plugin:1.7.4:minify(default-minify)项目my.project-frontend:目标com.samaxes.maven的执行default-minify:minify-maven-插件:1.7.4:缩小失败:basedir ./src/main/resources/public/app/.不存在

有谁知道该怎么做才能使这项工作?

以下有关的插件配置:

<!-- minify plugin -->
    <plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.4</version>
        <executions>
          <execution>
            <id>default-minify</id>
            <phase>prepare-package</phase><!-- When omitted defaults to 'process-resources' -->
            <configuration>
              <charset>UTF-8</charset>
              <skipMerge>true</skipMerge>
              <nosuffix>true</nosuffix>
              <closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
              <webappSourceDir>src/main/resources/public/app</webappSourceDir>
              <webappTargetDir>${project.build.outputDirectory}/public/app</webappTargetDir>

              <cssSourceDir>./</cssSourceDir>
              <cssSourceIncludes>
                <cssSourceInclude>**/*.css</cssSourceInclude>
              </cssSourceIncludes>

              <jsSourceDir>./</jsSourceDir>
              <jsSourceIncludes>
                <jsSourceInclude>**/*.js</jsSourceInclude>
              </jsSourceIncludes>

              <jsEngine>CLOSURE</jsEngine>
            </configuration>
            <goals>
              <goal>minify</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
 <!-- minify plugin end -->
Run Code Online (Sandbox Code Playgroud)

A_D*_*teo 6

我能够通过更改下面的配置条目来重现您的问题并进行修复

<webappSourceDir>src/main/resources/public/app</webappSourceDir>
Run Code Online (Sandbox Code Playgroud)

<webappSourceDir>${project.basedir}/src/main/resources/public/app</webappSourceDir>
Run Code Online (Sandbox Code Playgroud)

也就是说,添加标准${project.basedir}属性作为前缀.

有了这个,构建从模块本身成功,但也从父模块(reactor/aggregator构建)成功.

由于这个前缀,reactor构建将正确解析路径,指向构建期间当前的基目录(相关模块之一).


从官方Maven Builder模型文档

{project.basedir}包含该pom.xml文件的目录

因此,reactor构建将替换每个模块的此属性,指向包含模块pom.xml文件的目录(因此,模块的目录).从模块直接执行构建时,它也可以正常工作,显然是指向当前目录.

另请注意:${basedir}也可以使用,但有人赞成使用project.basedir,因此最好使用后者.