Automatic update of generated css files via m2e

北战南征 提交于 2019-12-04 05:29:39
Boj

There are two options:

Use an m2e specific profile

This is similar to the workaround you found, but a bit cleaner as it activates the profile only on m2e and you use a property to set an alternative value for when you package not using m2e.

You create an m2e specific profile that, when activated, will put the files directly in the m2e-wtp/web-resources/styles directory

<properties>      
    <lesscss.outputDirectory>${project.build.directory}/${project.build.finalName}/styles</lesscss.outputDirectory>
</properties>

<profiles>
    <profile>
        <id>m2e</id>
            <activation>
                <property>
                    <name>m2e.version</name>
                </property>
            </activation>
            <properties>
                <lesscss.outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</lesscss.outputDirectory>
            </properties>
    </profile>
</profiles>

<plugin>
    <groupId>org.lesscss</groupId>
    <artifactId>lesscss-maven-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <sourceDirectory>${project.basedir}/src/main/webapp/styles</sourceDirectory>
        <outputDirectory>${lesscss.outputDirectory}</outputDirectory>      
    </configuration>
    <executions>
        <execution>
            <goals>
                 <goal>compile</goal>
            </goals>
            <phase>process-sources</phase>
        </execution>
    </executions>
</plugin>

Source: https://github.com/marceloverdijk/lesscss-maven-plugin/issues/8

Use m2e-wro4j

It promises to:

execute wro4j-maven-plugin:run on Eclipse incremental builds, if a change is detected on css, js, less, json, sass resources under wro4j-maven-plugin's contextFolder (src/main/webapp by default)

Source: https://github.com/jbosstools/m2e-wro4j

The idea for my actual workaround was to modify the css file in target\m2e-wtp by "hand".

(First I tried to copy the css files from target\generated-sources to target\m2e-wtp with the maven-resource-plugin, but for a unkown reason, even the maven-resource-plugin was not coping when the filed css files in target\generated-sources gets updated.)

So I came up with this soution: let the lesscss-maven-plugin generate the files twice, one bunch to target\generated-sources and the second one to target\m2e-wtp. Of course the lesscss-maven-plugin has only one output folder, so one has to run the less:compile goal twice. (This is a bit slow, but it works.) Because one need the second bunch of css files only in eclipse I have added the second execution to an profile.

    <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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!