通过m2e自动更新生成的css文件 [英] Automatic update of generated css files via m2e

查看:176
本文介绍了通过m2e自动更新生成的css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 lesscss-maven-plugin 来生成不同的css文件到目标目录( target\generated-sources ),然后使用 maven-war-plugin 将此目录添加为webResouce。但是,m2e-plugin(1.0.0版)不会将这些文件复制到相应的网络资源文件夹中( m2e-wtp\web-resources ),当更改时。只有当我运行eclipsemaven / update project时,更改将会更新。但是,当文件更改时,我希望更改自动生效。这是我的pom配置:

 < plugin> 
< groupId> org.eclipse.m2e< / groupId>
< artifactId>生命周期映射< / 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>



....



 < 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>后端/后端-main.less< / include>
< include> frontend / frontend-main.less< / include>
< / includes>
< / configuration>
<执行>
< 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>样式< / targetPath>
< / resource>
< / webResources>
< / configuration>
< / plugin>


解决方案

有两个选项:



使用m2e特定配置文件



这与您发现的解决方法类似,但是仅在m2e上激活配置文件并且您使用属性为您打包不使用m2e时设置替代值。



您创建一个m2e特定的配置文件,在激活时将直接将文件放入 m2e-wtp / web-resources / styles 目录

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

<个人资料>
<个人资料>
< id> m2e< / id>
< activate>
< property>
< name> m2e.version< / name>
< / property>
< / activation>
<属性>
< 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>
<执行>
< execution>
< goals>
< goal> compile< / goal>
< / goals>
< phase> process-sources< / phase>
< / execution>
< / executions>
< / plugin>

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



使用m2e-wro4j



它承诺:


执行wro4j-maven-plugin:在Eclipse增量版本上运行,如果在wro4j-maven-plugin的contextFolder(默认情况下为src / main / webapp)中的css,js,less,json,sass资源上检测到更改: https://github.com/jbosstools/m2e-wro4j


I'm using the lesscss-maven-plugin to generate different css files to the target directory (target\generated-sources) and then use maven-war-plugin to add this directory as an webResouce. Those files will generate perfectly fine.

However the m2e-plugin (version 1.0.0) won't copy those files in the according web-resources folder (m2e-wtp\web-resources), when they have changed. Only when I run a eclipse "maven/update project" changes will be updated. But I want the changes to take affect automatically, when the files have changed. Here is my pom configuration:

<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>

....

<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>

解决方案

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

这篇关于通过m2e自动更新生成的css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆