3
votes

I'm looking for some information on how to get LESS compiling Bootstrap using the Maven plugin. I need to compile bootstrap with my less because I use bootstrap less in my files. Right now I have the maven plugin compiling less files into css, but it breaks when I try to get it to compile bootstrap less. I think this might be a version issue, but just want to know if anyone's been able to figure this out or has a better approach.

pom.xml

 <plugin>
     <groupId>org.lesscss</groupId>
     <artifactId>lesscss-maven-plugin</artifactId>
     <version>1.3.3</version>
     <configuration>
         <sourceDirectory>${project.basedir}/src/main/webapp/less</sourceDirectory>
         <outputDirectory>${project.build.directory}/${project.build.finalName}/css</outputDirectory>
         <compress>true</compress>
         <includes>
             <include>bootstrap/bootstrap.less</include>
             <include>test.less</include>
         </includes>
         <force>true</force>
     </configuration>
     <executions>
         <execution>
              <goals>
                  <goal>compile</goal>
              </goals>
         </execution>
     </executions>
</plugin>

I running the above in a run configuration that calls "clean lesscss:compile"

error

Failed to execute goal org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3:compile (default-cli) on project FastTest: Error while compiling LESS source: bootstrap\alerts.less: Syntax Error on line 57: [object Object] (compile.js#1) -> [Help 1]

I'm not sure why it's going after the first item in the list for bootstrap so I renamed bootstrap.less to see if it ran and this is what I got:

Failed to execute goal org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3:compile (default-cli) on project FastTest: Error while compiling LESS source: bootstrap\abootstrap.less: Syntax Error on line 686: [object Object] (compile.js#1) -> [Help 1]
5
Can you show the error messages and your pom file? - khmarbaise
Added what you're looking for above. - Ty Danielson
try to run it without <compress>true</compress>. - Michał Rybak
also: what's in alerts.less, line 57? what is test.less? how does bootstrap.less look, if it's not standard? - Michał Rybak
alerts.less is the first .less file for bootstrap. It's not supposed to compile right away bootstrap.less should. test.less is a very minimal .less file I made just to make sure it compiles. It does. I removed the compress and it still won't run bootstrap.less first and compile correctly. I also can't figure out what version of less bootstrap is using, that would be nice to know if it's breaking because the versions aren't correct. - Ty Danielson

5 Answers

2
votes

You are not compiling your code with correct plugin.

You are defining:

<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>

But from output it is obvious that a different plugin was triggered:

org.codehaus.mojo:lesscss-maven-plugin:1.0-beta-3  
2
votes

Seems a newer version of less is required for the maven plugin since bootstrap uses features that require less version 1.4.0

2
votes

Your plugin-version issue notwithstanding, you can override the compiler being used by the Maven Plugin...

Download the latest lesscss JS file from lesscss.org, and put it in your project's scripts/js folder, then add a lessJs node into your plugin's configuration:

<configuration>
  <lessJs>${project.basedir}/.../less.?.?.?.min.js</lessJs>
  ...
</configuration>

Now the plugin will use the JS file to compile, instead of it's own built-in, often outdated compiler.

I think the latest JS release is now 1.6.3.

Hope this helps!

Tze

2
votes

If you are using the newest version of Bootstrap you will need Less 1.6.x to compile the Less files.

See http://blog.getbootstrap.com/2014/01/30/bootstrap-3-1-0-released/ that writes:

We've switched from Recess to grunt-contrib-less for our compiler, giving us access to Less 1.6.x (as opposed to 1.3.x with Recess).

The official Less Maven Plugin org.lesscss:lesscss-maven-plugin that you use does currently only support Less 1.3 and is not actively maintained at the moment. But I released a fork of it to Maven Central yesterday that supports Less 1.6.1 and contains other open pull requests from the plugin. It is de.sandroboehme.lesscss:lesscss-maven-plugin:1.6.1.1.0 from https://github.com/sandroboehme/lesscss-java. Using it could solve your problem.

BTW: If somebody happens to be interested, contributers are wanted for the official Maven plugin. See https://github.com/marceloverdijk/lesscss-maven-plugin/issues/39

0
votes

In the mean time I would use the Frontend Maven Plugin. See https://github.com/eirslett/frontend-maven-plugin