简体   繁体   English

yuicompressor Maven 不工作

[英]yuicompressor maven is not working

I am working in Spring boot web application with maven build.我正在使用 Maven 构建在 Spring Boot Web 应用程序中工作。 I want to compress all js & css files.我想压缩所有 js 和 css 文件。 I have chosen YUI compression.我选择了 YUI 压缩。 When I build my application yui compression not happened.当我构建我的应用程序时,yui 压缩没有发生。 I am getting following message for all js & css files.我收到所有 js 和 css 文件的以下消息。

[INFO] nothing to do, **css\\base.css is younger than original, use 'force' option or clean your target [INFO] 无事可做,**css\\base.css 比原始文件年轻,使用“强制”选项或清理目标

What I am missing ?我缺少什么?

Here is my pom.xml这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <groupId>MyApp</groupId>
      <artifactId>MyApp</artifactId>
      <version>0.0.1</version>
      <packaging>war</packaging>
    <!--   <url>http://maven.apache.org</url> -->

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.2.RELEASE</version>
        </parent>

        <dependencies>
            my dependencies
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <executable>true</executable>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>yuicompressor-maven-plugin</artifactId>
                    <version>1.5.1</version>
                    <executions>
                      <execution>
                        <goals>
                          <goal>compress</goal>
                        </goals>
                      </execution>
                    </executions>        
                    <configuration>
                      <nosuffix>true</nosuffix>
                    </configuration>
                  </plugin> 
            </plugins>
        </build>
    </project>

Project structure :项目结构: 在此处输入图片说明

It's not an error and works as expected.这不是错误并且按预期工作。 The plugin creates a minified version of the resource only when it's minified version doesn't exist or when source file has been changed.仅当资源的缩小版本不存在或源文件已更改时,插件才会创建资源的缩小版本。 When plugin found that minified version was created later than source file, it doesn't do minification and assumes that nothing to be done.当插件发现缩小版本的创建时间晚于源文件时,它不会进行缩小并假设什么都不做。

As you can see, message suggests you to use force option (in this case, minified version will be always generated but it will be slower) or clean the target (execute mvn clean to remove all generated files so they will be generated again).如您所见,消息建议您使用force选项(在这种情况下,将始终生成缩小版本,但速度会更慢)或清理目标(执行mvn clean以删除所有生成的文件,以便再次生成它们)。


UPDATED:更新:

I was able to reproduce the issue.我能够重现这个问题。 It happens because yuicompressor-maven-plugin is being executed after maven-resource-plugin.这是因为 yuicompressor-maven-plugin 是在 maven-resource-plugin 之后执行的。 The former was copied all the files from src/main/resources to the target directory and when yuicompressor was being executed, it found that the files already here (non-minified of course) and show this message.前者将src/main/resources中的所有文件复制到target目录,当 yuicompressor 执行时,它发现文件已经在这里(当然是非缩小的)并显示此消息。

To fix this, first, we need to configure resource plugin to exclude resources:为了解决这个问题,首先,我们需要配置资源插件来排除资源:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources/public</directory>
            <excludes>
                <exclude>*.js</exclude>
                <exclude>*/*.js</exclude>
            </excludes>
        </resource>
    </resources>
</build>

But it didn't solve it because after that I found that yuicompressor doesn't process these files.但它没有解决它,因为之后我发现yuicompressor不处理这些文件。 This is because the plugin was looking in the wrong directory and we have to configure it also:这是因为插件在错误的目录中查找,我们还必须对其进行配置:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.5.1</version>
    ...
    <configuration>
        <nosuffix>true</nosuffix>
        <sourceDirectory>src/main/resources/public</sourceDirectory>
    </configuration>
</plugin>

Use -Dmaven.clean.failOnError=false to mvn command.使用-Dmaven.clean.failOnError=false到 mvn 命令。 example: mvn clean -Dmaven.clean.failOnError=false示例: mvn clean -Dmaven.clean.failOnError=false

Just by adding Force option I resolved this issue:只需添加Force选项,我就解决了这个问题:

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.5.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>

                <force>true</force>

                <sourceDirectory>src/main/resources/static</sourceDirectory>
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
               
                <excludes>
                    <exclude>**/*.min.js</exclude>
                    <exclude>**/*.min.css</exclude>
                </excludes>
            </configuration>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM