Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Concatenate .less-files into a single file before compile #19

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/src/it/concatenate/src/main/less/less.less

.classpath
.project
.settings/
target/
.svn
61 changes: 41 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Official LESS CSS Maven Plugin
==============================
LESS CSS Maven Plugin - SJV
===========================
For official versoin see: https://github.com/marceloverdijk/lesscss-maven-plugin

Usage
-----
Expand All @@ -9,7 +10,7 @@ Declare the plugin and its goals. The process-sources phase is bound to by defau
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.0</version>
<version>1.3.3-SJV</version>
<executions>
<execution>
<goals>
Expand All @@ -28,7 +29,7 @@ Example configuration for web project
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.0</version>
<version>1.3.3-SJV</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/less</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/css</outputDirectory>
Expand All @@ -45,6 +46,37 @@ Example configuration for web project
</execution>
</executions>
</plugin>

Exmple configuration with two configurations....
------------------------------------------------
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3-SJV</version>
<configuration>
<configurationItems>
<configurationItem>
<!-- Common .js from framework -->
<sourceDirectory>${project.basedir}/src/main/less/common</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/css/common</outputDirectory>
<compress>true</compress>
</configurationItem>
<!-- Project specific -->
<sourceDirectory>${project.basedir}/src/main/webapp/less/project</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/css/project</outputDirectory>
<compress>false</compress>
<configurationItem>
</configurationItem>
</configurationItems>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>


All configuration options
Expand All @@ -58,29 +90,18 @@ All configuration options
+ force (boolean) - When true forces the LESS compiler to always compile the LESS sources. By default LESS sources are only compiled when modified (including imports) or the CSS stylesheet does not exists. Default value is: false.
+ includes (String[]) - List of files to include. Specified as fileset patterns which are relative to the source directory. Default value is: { "**\/*.less" }
+ lessJs (String) - The location of the LESS JavasSript file.

+ concatenate (boolean) - When true all less-files will be concatenated into a single file before compiling to css
+ watch (boolean) - When true the plugin watches the sourceDirectory and recompiles the included files after they changed. Instead of configuring it in the pom you can use that option at the command line like this "mvn lesscss:compile -Dlesscss.watch=true". Then it doesn't interfere with other maven lifecycle phases and you can just kill the watch process e.g. with crtl-c. Default value is: false.
+ watchInterval (int) - The interval in milliseconds the plugin waits between the check for file changes. Default value is: 1000 ms.
+ configurationItems - a list of configurationItem.
+ configurationItem - a custom class. Holds a separate configuration, eg all of the above.

List sources
------------

To list the LESS sources in your project the lesscss:list goal can be used. It lists the LESS sources and it's imports based on sourceDirectory and optionally includes and excludes configuration options.


Support
-------

Have a question, or found an issue? Just create a issue: https://github.com/marceloverdijk/lesscss-maven-plugin/issues


Authors
-------

**Marcel Overdijk**

+ [email protected]
+ http://twitter.com/marceloverdijk
+ http://github.com/marceloverdijk


Copyright and License
---------------------
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.3.3-SJV-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Official LESS CSS Maven Plugin</name>
<description>Official LESS CSS Maven Plugin</description>
Expand Down Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.2</version>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -51,7 +51,7 @@
<dependency>
<groupId>org.lesscss</groupId>
<artifactId>lesscss</artifactId>
<version>1.3.0</version>
<version>1.3.3.SJV-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/it/concatenate/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean compile
26 changes: 26 additions & 0 deletions src/it/concatenate/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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>org.lesscss.it</groupId>
<artifactId>concatenate</artifactId>
<version>testing</version>
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<concatenateTo>concatenated.less</concatenateTo>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
8 changes: 8 additions & 0 deletions src/it/concatenate/src/main/less/test.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


#header {
color: @color;
}
h2 {
color: @color;
}
2 changes: 2 additions & 0 deletions src/it/concatenate/src/main/less/variables.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@color: #4d926f;

3 changes: 3 additions & 0 deletions src/it/concatenate/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
assert new File(basedir, "target/concatenated.css").exists()
assert !new File(basedir, "target/test.css").exists()
assert !new File(basedir, "target/variables.css").exists()
1 change: 1 addition & 0 deletions src/it/multiple-config/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean compile
38 changes: 38 additions & 0 deletions src/it/multiple-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.lesscss.it</groupId>
<artifactId>basic</artifactId>
<version>testing</version>

<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<configurationItems>
<configurationItem>
<sourceDirectory>${project.basedir}/src/main/less1</sourceDirectory>
<outputDirectory>${project.build.directory}/css1</outputDirectory>
</configurationItem>
<configurationItem>
<sourceDirectory>${project.basedir}/src/main/less2</sourceDirectory>
<outputDirectory>${project.build.directory}/css2</outputDirectory>
</configurationItem>
</configurationItems>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
8 changes: 8 additions & 0 deletions src/it/multiple-config/src/main/less1/firstTest.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@color: #4d926f;

#header {
color: @color;
}
h2 {
color: @color;
}
8 changes: 8 additions & 0 deletions src/it/multiple-config/src/main/less2/secondTest.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@color: #4d926f;

#header {
color: @color;
}
h2 {
color: @color;
}
2 changes: 2 additions & 0 deletions src/it/multiple-config/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assert new File(basedir, "target/css1/firstTest.css").exists()
assert new File(basedir, "target/css2/secondTest.css").exists()
27 changes: 22 additions & 5 deletions src/main/java/org/lesscss/mojo/AbstractLessCssMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.lesscss.mojo;

import java.io.File;
import java.util.List;

import org.apache.maven.plugin.AbstractMojo;
import org.codehaus.plexus.util.Scanner;
Expand All @@ -30,6 +31,13 @@ public abstract class AbstractLessCssMojo extends AbstractMojo {
/** @component */
protected BuildContext buildContext;

/**
* Using configurationItems allows you to have several different compilations on a single project
*
* @parameter
*/
protected List<ConfigurationItem> configurationItems;

/**
* The source directory containing the LESS sources.
*
Expand All @@ -43,7 +51,7 @@ public abstract class AbstractLessCssMojo extends AbstractMojo {
*
* @parameter
*/
protected String[] includes = new String[] { "**/*.less" };
protected String[] includes = new String[] { INCLUDES_DEFAULT_VALUE };

/**
* List of files to exclude. Specified as fileset patterns which are relative to the source directory.
Expand All @@ -52,16 +60,25 @@ public abstract class AbstractLessCssMojo extends AbstractMojo {
*/
protected String[] excludes = new String[] {};

static final String INCLUDES_DEFAULT_VALUE = "**/*.less";

/**
* Scans for the LESS sources that should be compiled.
*
* @return The list of LESS sources.
*/
protected String[] getIncludedFiles() {
Scanner scanner = buildContext.newScanner(sourceDirectory, true);
scanner.setIncludes(includes);
scanner.setExcludes(excludes);
protected String[] getIncludedFiles(ConfigurationItem configurationItem) {
Scanner scanner = buildContext.newScanner(configurationItem.getSourceDirectory(), true);
scanner.setIncludes(configurationItem.getIncludes());
scanner.setExcludes(configurationItem.getExcludes());
scanner.scan();
return scanner.getIncludedFiles();
}

/**
* Get configuration
*
* @return a list of ConfigurationItems read from the plugin-configuration
*/
protected abstract List<ConfigurationItem> getConfiguration();
}
Loading