minify frontend with minify-maven-plugin
Asked Answered
D

2

5

I'm using the maven plugin minify-maven-plugin in order to minify my frontend project. This works fine when I go over dos box to the frontend project and execute mvn clean install but when I execute mvn clean install in the main pom in my reactor project then I get the following exception:

Failed to execute goal com.samaxes.maven:minify-maven-plugin:1.7.4:minify (default-minify) on project my.project-frontend: Execution default-minify of goal com.samaxes.maven:minify-maven-plugin:1.7.4:minify failed: basedir ./src/main/resources/public/app/. does not exis

Does anyone know what to do in order to make this work?

Below the concerned plugin configuration:

<!-- 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 -->
Deadlight answered 31/3, 2016 at 17:3 Comment(2)
basedir ./src/main/resources/public/app/. does not exist. That's clear no? Does the folder exist?Sublime
Yes, it does exist, otherwise the project could not be build when I execute mvn clean install in the project. The problem must be with the path concerning the reactor- project.Deadlight
I
7

I was able to reproduce your issue and fix it by changing the configuration entry below

<webappSourceDir>src/main/resources/public/app</webappSourceDir>

to

<webappSourceDir>${project.basedir}/src/main/resources/public/app</webappSourceDir>

That is, adding the standard ${project.basedir} property as a prefix.

With that, the build was successful from the module itself but also from the parent one (the reactor/aggregator build).

Thanks to this prefix, the reactor build will properly resolve the path, pointing at the current base directory (the one of the concerned module) during the build.


From official Maven Builder model documentation

{project.basedir} the directory containing the pom.xml file

Hence, the reactor build will replace this property for each module, pointing at the directory containing the module pom.xml file (hence, the directory of the module). It will also work properly when executing the build from the module directly, obviously pointing at the current directory.

Also note: ${basedir} would also work but it is deprecated in favor of project.basedir, hence better to use the latter.

Initial answered 2/4, 2016 at 21:14 Comment(2)
Thanks a lot, I will test it and afterwards will give you the 100 Points.Deadlight
@user3318489 glad to see it helped out!, since you assigned the bounty I guess it was fine as a solution. In that case I would also suggest to accept it as answer √ so that the question doesn't statistically appear as unanswered. ThanksInitial
G
0

You cam minify as:

<plugin>
            <groupId>com.samaxes.maven</groupId>
            <artifactId>minify-maven-plugin</artifactId>
            <version>1.7.4</version>
            <executions>
               <execution>
                  <id>minify-css</id>
                  <configuration>
                     <charset>utf-8</charset>
                     <skipMerge>true</skipMerge>
                     <statistics>true</statistics>
                     <cssSourceDir>css</cssSourceDir>
                     <cssTargetDir>css/min</cssTargetDir>
                     <cssSourceIncludes>
                        <cssSourceInclude>*.css</cssSourceInclude>
                     </cssSourceIncludes>
                  </configuration>
                  <goals>
                     <goal>minify</goal>
                  </goals>
               </execution>
               <execution>
                  <id>minify-js-cfl</id>
                  <configuration>
                     <charset>utf-8</charset>
                     <skipMerge>true</skipMerge>
                     <statistics>true</statistics>
                     <jsSourceDir>js/xyz/modules/cfl</jsSourceDir>
                     <jsTargetDir>js/xyz/modules/cfl/min</jsTargetDir>
                     <jsSourceIncludes>
                        <jsSourceInclude>*.js</jsSourceInclude>
                     </jsSourceIncludes>
                  </configuration>
                  <goals>
                     <goal>minify</goal>
                  </goals>
               </execution>
               <execution>
Globule answered 31/5, 2016 at 16:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.