Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place minified files into jar

Tags:

maven

minify

I will use the maven dependency com.samaxes.maven#minify-maven-plugin to minify my frontend project. This frontend- project is packaged into a jar (java archive) - so I have no war file because I use Spring boot.

With the configuration at the bottom *.min.js and *.min.css files are generated but they are not pacakged into jar file. I have read some threads and I have tried something but with no success: in the JAR file there are still the unminified css and js files.

Does anyone have any hint what I can do. I have a lot of css and js files in my project in different folder structures and the minified files should be placed in the same place like the unminified files are.

<build>
<plugins>
  <plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>minify-maven-plugin</artifactId>
    <version>1.7.4</version>
    <executions>
      <execution>
        <id>default-minify</id>
        <phase>package</phase>
        <configuration>
          <charset>UTF-8</charset>
          <skipMerge>true</skipMerge>
          <nosuffix>true</nosuffix>
          <closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
          <webappSourceDir>src/main/resources</webappSourceDir>
          <cssSourceDir>./</cssSourceDir>
          <cssTargetDir>./minified</cssTargetDir>
          <cssSourceIncludes>
            <cssSourceInclude>**/*.css</cssSourceInclude>
          </cssSourceIncludes>
          <cssSourceExcludes>
            <cssSourceExclude>**/*.min.css</cssSourceExclude>
          </cssSourceExcludes>
          <jsSourceIncludes>
            <jsSourceInclude>**/*.js</jsSourceInclude>
          </jsSourceIncludes>
          <jsSourceExcludes>
            <jsSourceExclude>**/*.min.js</jsSourceExclude>
          </jsSourceExcludes>
          <jsEngine>CLOSURE</jsEngine>
        </configuration>
        <goals>
          <goal>minify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

[EDIT]

I have edit the Maven plugin in this way. I really have to use src/main/recoures - it a specification at our project.

My problem now is that the files in the different folders unter the under the main folder path public/app are minified BUT the folders with the minified files are at same level than my public folder is.

So I would need something like this:

<webappTargetDir>**public/app/**${project.build.outputDirectory}</webappTargetDir>

Is there a possibility to do it like this?

<build>
<plugins>
  <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>
          <closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
          <webappSourceDir>src/main/resources/public/app</webappSourceDir>
          <webappTargetDir>${project.build.outputDirectory}</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>

With the minify-maven-plugin configuration above I get the following folder structure at the left side but I would need the folder structure at the rigth side. Is there any possibility to do that?

Current and needed folder structure

like image 304
quma Avatar asked Jan 13 '16 14:01

quma


1 Answers

The files are copied relatively from webappSourceDir to webappTargetDir. So if you want the structure to match, you should use similar patterns for those. Meaning, it should be

<webappSourceDir>src/main/resources</webappSourceDir>
<webappTargetDir>${project.build.outputDirectory}</webappTargetDir>

or

<webappSourceDir>src/main/resources/public/app</webappSourceDir>
<webappTargetDir>${project.build.outputDirectory}/public/app</webappTargetDir>

I've commited the working example here

like image 80
Dzmitry Paulenka Avatar answered Oct 01 '22 05:10

Dzmitry Paulenka