通过m2e自动更新生成的css文件

mej*_*joz 6 eclipse m2eclipse less maven-plugin maven

我正在使用它lesscss-maven-plugin生成不同的css文件到目标目录(target\generated-sources),然后用于maven-war-plugin将此目录添加为webResouce.这些文件将生成完美的.

但是,m2e-plugin(版本1.0.0)在更改m2e-wtp\web-resources时不会复制相应web-resources文件夹()中的那些文件.只有当我运行eclipse"maven/update project"时,才会更新更改.但我希望更改在文件更改时自动生效.这是我的pom配置:

<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
    <lifecycleMappingMetadata>
        <pluginExecutions><pluginExecution>
                <pluginExecutionFilter>
                    <groupId>org.lesscss</groupId>
                    <artifactId>lesscss-maven-plugin</artifactId>
                    <versionRange>[1.3.3]</versionRange>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </pluginExecutionFilter>
                <action>
                    <execute>
                        <runOnIncremental>true</runOnIncremental>
                        <runOnConfiguration>true</runOnConfiguration>
                    </execute>
                </action>
            </pluginExecution>  
        </pluginExecutions>
    </lifecycleMappingMetadata>
</configuration>
Run Code Online (Sandbox Code Playgroud)

....

<plugin>
    <groupId>org.lesscss</groupId>
    <artifactId>lesscss-maven-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <sourceDirectory>${project.basedir}/src/main/less</sourceDirectory>
        <outputDirectory>${project.build.directory}/generated-sources/styles</outputDirectory>
        <lessJs>${project.basedir}/tools/less/less-1.7.0.min.js</lessJs>
        <includes>
            <include>backend/backend-main.less</include>
            <include>frontend/frontend-main.less</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <phase>process-resources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>              
        <webResources>
            <resource>
                <directory>${project.build.directory}/generated-sources/styles</directory>
                <targetPath>styles</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Ral*_*lph 1

target\m2e-wtp我实际解决方法的想法是“手动”修改 css 文件。

(首先,我尝试使用 maven-resource-plugin 将 css 文件复制到target\generated-sources,但由于未知的原因,当提交的 css 文件更新target\m2e-wtp时,即使 maven-resource-plugin 也无法应对。)target\generated-sources

所以我想出了这个解决方案:让lesscss-maven-plugin文件生成两次,一组生成target\generated-sourcestarget\m2e-wtp. 当然,lesscss-maven-plugin只有一个输出文件夹,因此必须运行 less: compilegoal 两次。(这有点慢,但它有效。) 因为只在 eclipse 中需要第二堆 css 文件,所以我已将第二个执行添加到配置文件中。

    <profile>
        <id>less-eclipse-m2e-workarround</id>
        <!-- 
            problem: Eclipse is not updating m2e-wtp folder when css files in generated-sources get modified
            workarround: generate the css twice: the normal nonce for generated-sources and a second bunch (only
            for eclipse) directly into m2e-wtp folder
            to enable this profile add the profile-id to: project/properties/maven/active maven profiles
            details: http://stackoverflow.com/questions/23521410/automatic-update-of-generated-css-files-via-m2e
        -->
        <build>
            <plugins>
                <plugin>
                    <groupId>org.lesscss</groupId>
                    <artifactId>lesscss-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>for-eclipse</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>compile</goal>                            
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
Run Code Online (Sandbox Code Playgroud)