eclipsemavenlessm2em2e-wtp

Compiling LESS CSS with Maven and m2e-wtp


I'm trying to compile LESS CSS files with lesscss-maven-plugin, both in pure maven (with command line) and within Eclipse (Juno).

In the lesscss-maven-plugin, I need to define an output directory, but I noticed that in Eclipse WTP copies files from target/m2e-wtp in my server (JBoss), but that this directory is ignored by the war plugin of Maven.

I succeeded to reach my goal with Maven profiles : in Eclipse I use a m2e profile configured in Project settings, so I can define two different destination folders depending on I build in Eclipse or not.

Here is my 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>com.dgadev.motd</groupId>
    <artifactId>motd</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <properties>
        <maven.compiler.source>7</maven.compiler.source>
        <maven.compiler.target>7</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
            ....
    </dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.lesscss</groupId>
            <artifactId>lesscss-maven-plugin</artifactId>
            <version>1.3.3</version>
            <configuration>
                <outputDirectory>${project.build.directory}/resources/css</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>m2e</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.lesscss</groupId>
                    <artifactId>lesscss-maven-plugin</artifactId>
                    <version>1.3.3</version>
                    <configuration>
                        <outputDirectory>${project.build.directory}/m2e-wtp/web-resources/resources/css</outputDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

This works, but is there a better way to do this, without the profile trick ?


Solution

  • I found another solution with a different less compiler : wro4j. With this compiler, both exists maven and m2e plugins. In addition, a tutorial (for building boostrap) can be found here: m2e-wro4j