yuicompressor maven plugin i Maven-war-plugin

I ' ve borykał się z coraz ten plugin grać ładnie z maven-war-plugin dla kilku godzin teraz i pomyślałem, że nadszedł czas, aby poprosić o pomoc. Mam wtyczkę zdefiniowaną w następujący sposób:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.0</version>
    <executions>
        <execution>
            <id>compressyui</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
            <configuration>
                <nosuffix>true</nosuffix>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <jswarn>false</jswarn>
            </configuration>
        </execution>
    </executions>
</plugin>

Jeśli usunę nosuffix = true to widzę skompresowany / minified-min.Pliki js dostać się do wojny zgodnie z oczekiwaniami, ale z tą flagą na Są one nadpisane przez maven-war-plugin (zakładam), gdy buduje plik wojny. Naprawdę potrzebuję, żeby nazwy plików pozostały takie same. chociaż ... czy ktoś ma pojęcie, co muszę zmienić, aby używać tych samych nazw plików i nadal dostać zminifikowane wersje do ostatecznej wojny?

Author: Jean-Rémy Revy, 2012-07-15

6 answers

OK. W końcu to rozgryzłem. Musisz zdefiniować <webappDirectory> w wtyczce yuicompressor, którą następnie można nazwać <resource> w wtyczce Maven-war. W poniższym przykładzie używam <directory>${project.build.directory}/min</directory>

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.0</version>
    <executions>
        <execution>
            <id>compressyui</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
            <configuration>
                <nosuffix>true</nosuffix>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <webappDirectory>${project.build.directory}/min</webappDirectory>
                <jswarn>false</jswarn>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
            <configuration>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <encoding>UTF-8</encoding>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
        <encoding>UTF-8</encoding>
        <webResources>
            <resource>
                <directory>${project.build.directory}/min</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>
 26
Author: Dave Maple,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-15 23:06:26

Wystarczy skonfigurować' warSourceExcludes ' na wtyczce WAR.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
    </configuration>
</plugin>
 8
Author: Thrawn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-26 04:42:24

Chciałbym dodać konfigurację, która działała dla mnie:

Po pierwsze, aby naprawić M2E narzekanie na "wykonanie wtyczki nie objęte cyklem życia" dodałem następujący pom rodzica pobrany z ten post :

  <pluginManagement>
    <plugins>
        <!--This plugin's configuration is used to store Eclipse 
            m2e settings only. It has no influence on the Maven build itself. -->
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>net.alchim31.maven</groupId>                               
                                <artifactId>yuicompressor-maven-plugin</artifactId>
                                <versionRange>[1.0.0,)</versionRange>
                                <goals>
                                    <goal>compress</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <execute />
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

Potem w war pom wstawiłem:

<build>
    <plugins>
        <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
        <execution>
            <goals>
              <goal>compress</goal>
            </goals>
            <configuration>
               <linebreakpos>300</linebreakpos>
               <excludes>
                 <exclude>**/*-min.js</exclude>
                 <exclude>**/*.min.js</exclude>
                 <exclude>**/*-min.css</exclude>
                 <exclude>**/*.min.css</exclude>
               </excludes>              
               <nosuffix>true</nosuffix>
            </configuration>
        </execution>
        </executions>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Generuje minifikowane pliki css i js w docelowym katalogu budowania projektu, z wyłączeniem oryginalnych plików.

Mam nadzieję, że to oszczędzi komuś czasu.
 3
Author: TooSerious,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:32:04

To jest moja konfiguracja i działa dobrze w moim projekcie maven web:

    <!-- js/css compress -->
<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <excludes>
            <exclude>**/*-min.js</exclude>
            <exclude>**/*.min.js</exclude>
            <exclude>**/*-min.css</exclude>
            <exclude>**/*.min.css</exclude>
        </excludes>
        <jswarn>false</jswarn>
        <nosuffix>true</nosuffix>
    </configuration>
    <executions>
        <execution>
            <id>compress_js_css</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<!-- war -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <webResources>
            <resource>
                <directory>${project.build.directory}/${project.build.finalName}/resources</directory>
                <targetPath>/resources</targetPath>
                <filtering>false</filtering>
            </resource>
        </webResources>
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
    </configuration>
</plugin>
 2
Author: vivia,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-26 07:51:39

Podejście, którego używam, jest nieco inne.

Najpierw skonfigurowałem moje IDE do uruchamiania mvn process-resources przed kompilacją / pakowaniem . W ten sposób pliki są tworzone przed wojną.

Jest to bardzo ważne, aby ustawić <nosuffix>false</nosuffix> i <outputDirectory>${basedir}/src/main/resources/</outputDirectory>, aby pliki mogły być tworzone w tym samym katalogu bez zastępowania oryginalnych plików źródłowych.

 <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <preProcessAggregates>false</preProcessAggregates>
        <excludes>
            <exclude>**/*-min.js</exclude>
            <exclude>**/*.min.js</exclude>
            <exclude>**/*-min.css</exclude>
            <exclude>**/*.min.css</exclude>
        </excludes>
        <jswarn>false</jswarn>
        <nosuffix>false</nosuffix> <!-- VERY IMPORTANT WILL REPLACE YOUR FILES IF YOU SET nosuffix TO TRUE OR DONT SET IT AT ALL -->
        <outputDirectory>${basedir}/src/main/resources/</outputDirectory> <!-- by default the plugin will copy the minimized version to target directory -->
        <failOnWarning>false</failOnWarning>
    </configuration>

    <executions>
        <execution>
            <id>compress_js_css</id>
                <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
        </execution>
    </executions>
</plugin>
 0
Author: lmiguelmh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-12 16:53:31

Jak mówi Jakob Kruse, musisz poradzić sobie z *.js, ale nie *./ min.js, więc moje konfiguracje są poniżej, proszę zauważyć użycie %regex []:

			<plugin>
			    <groupId>net.alchim31.maven</groupId>
			    <artifactId>yuicompressor-maven-plugin</artifactId>
			    <version>1.4.0</version>
			    <executions>
			        <execution>
			            <id>compressyui</id>
			            <phase>process-resources</phase>
			            <goals>
			                <goal>compress</goal>
			            </goals>
			            <configuration>
			                <nosuffix>true</nosuffix>
			                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
			                <webappDirectory>${project.build.directory}/min</webappDirectory>
			                <jswarn>false</jswarn>		
				        <excludes>
				            <exclude>**/*-min.js</exclude>
				            <exclude>**/*.min.js</exclude>
				            <exclude>**/*-min.css</exclude>
				            <exclude>**/*.min.css</exclude>

				            <exclude>**/jquery.window.js</exclude>
				            ......
				            <exclude>**/compile.js</exclude>
				        </excludes>
			            </configuration>
			        </execution>
			    </executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<warSourceDirectory>WebContent</warSourceDirectory>					
					<packagingExcludes>servlet-api*.jar,target/test-classes/*</packagingExcludes>
					<warSourceExcludes>test/**,%regex[.*(!min).js],%regex[.*(!min).css]</warSourceExcludes>
				
					<webResources>
 					            <resource>
					                <directory>${project.build.directory}/min</directory>
					            </resource>
					</webResources>
				
				</configuration>
			</plugin>
 0
Author: Yu Jiaao,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-22 02:30:44