Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minify frontend with minify-maven-plugin

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 -->
like image 216
quma Avatar asked Mar 31 '16 17:03

quma


People also ask

Should I minify CSS and JavaScript?

It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.


1 Answers

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.

like image 193
A_Di-Matteo Avatar answered Nov 02 '22 09:11

A_Di-Matteo