Bootstrap, LESS and Maven plugin - maven

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]

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

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

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

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

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

Related

liferay-maven-plugin + direct-deploy configuration for DXP

I'm currently on Liferay 6.2 (with Tomcat), and I can configure the liferay-maven-plugin in my Liferay hook project's maven pom.xml as below, in order to pre-process my hook WAR for hot deployment (using the direct-deploy goal of the plugin).
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>6.2.1</version>
<executions>
<execution>
<id>pre-process-war</id>
<phase>package</phase>
<goals>
<goal>direct-deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<appServerDeployDir>${project.basedir}/target/liferay-pre-process</appServerDeployDir>
<liferayVersion>6.2.1</liferayVersion>
<pluginType>hook</pluginType>
<unpackWar>false</unpackWar>
</configuration>
</plugin>
I'm now trying to migrate this hook to Liferay 7.2.1 CE. There is no plan to redesign this as an OSGI module at the moment i.e. it would continue to be packaged as a WAR. So how would my new direct-deploy configuration look like, with Liferay 7.2.1? Specifically:
a) Can I continue using the same Maven plugin? I see from this doc that the liferay-maven-plugin has been "removed", yet my understanding from other help pages is that this plugin should not be used only with the newer, OSGI-module style plugins (the latter makes more sense to me).
b) If I can continue using the same Maven plugin, which version of the plugin works with 7.2.1? Also, which liferayVersion value should I use here? I tried a bunch of combinations and none of them worked.
For instance, I first tried liferayVersion 7.2.1 but the build failed while running the direct-deploy goal, since Maven didn't find a com.liferay.portal:portal-web artifact with that version. So I tried the latest version of that artifact from Maven Central, which is 7.0.2, as my liferayVersion. But the build failed again, this time because it couldn't locate the corresponding version of com.liferay.portal:portal-service. There's no 7.x version of portal-service though, which makes sense because it's been replaced with the portal-kernel artifact. Not specifying liferayVersion doesn't work either.
I received a response in a Liferay forum which suggests that the liferay-maven-plugin has indeed been removed in Liferay 7.x, and so the only option left is to copy the WAR to Liferay's deploy folder and let it do the pre-processing at deploy time (as opposed to doing this at build time, with the Maven plugin). Given the lack of alternatives at this point, that seems to be the only way forward (and it works).

Is maven-download-plugin not portable, or am I crazy?

TL;DR: I stumbled upon a situation where my pom.xml works fine on Windows, but fails on Linux. Since I'm rather new to maven, I'm not sure whether it's a common situation, or if I messed up somewhere.
More details:
I use the maven-download-plugin like this:
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>maven-download-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>get-stuff</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://myUrl/my.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
On Windows it works like a charm (ie: it downloads and unpack).
On Linux, it fails with the following error:
[ERROR] Failed to execute goal com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget (get-moab)
on project my-project: Execution get-stuff of goal com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget failed:
An API incompatibility was encountered while executing com.googlecode.maven-download-plugin:maven-download-plugin:1.1.0:wget: java.lang.NoSuchMethodError: org.codehaus.plexus.util.cli.Commandline.createArg()Lorg/codehaus/plexus/util/cli/Arg;
I found a workaround (<unpack>false</unpack>, and then "manually" unpack with antrun), but my pom.xml looked better without those additional 15 lines...
To put it in a nutshell:
Is it actually a portability issue, or have I messed up somewhere?
If it's an portability issue: is it common with maven, or am I unlucky on this one?
More technical details:
I used the same plugin both on Linux and Windows (same version, same maven repository)
It failed on a Centos, and a VM with Ubuntu 12.04
My first troubleshooting step when a build works on one machine and not another is to clean out the local Maven repository on the failing machine, and let Maven re-download all of the artifacts. That's often enough to fix the problem.
If the build fails with the same error, then I clean out the local repository on the working machine and build. Usually then I see that I've missed a dependency in the POM that just happened to exist in my local repository already. Fixing the POM often makes the build work on both systems.
Did you check the Maven versions (mvn -version)? org.codehaus.plexus.util is a dependency of Maven Core, so if maven-download-plugin is running under a different version of Maven it was compiled for, this would explain the error.

How do I write a maven plugin which actually runs?

The instructions here seem very clear:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
However, the first problem I run into is that the dependencies are wrong. I also needed to reference the maven-plugin-annotations dependency.
Then, when I attempt to run I get the "No plugin descriptor found at META-INF/maven/plugin.xml" error. I haven't figured out what to do about that.
I've found lots of pages referencing the maven-plugin-plugin, but I can't figure out how to add it to the pom so that it actually does anything which allows my own plugin to run.
Is there an updated version of the plugin development instructions which actually mentions the need to use maven-plugin-plugin?
If I can't get this to work I'm just going to go back to using exec-maven-plugin. It's uglier, but at least it works easily.
There are actually several terrific resources from Sonatype for learning how to write plugins:
Maven the Complete Reference: Writing Plugins
Maven Cookbook: Creating an Ant Maven Plugin
Maven Cookbook: Writing Plugins in Groovy
If I recall correctly, you need to configure the maven-plugin-plugin this way to avoid the "No plugin descriptor found..." issue.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
I forked a simple GitHub project called maven-wrapper (port of the Gradle wrapper) to make it a Maven plugin.
"It should be easy" for you to figure out pieces that you may eventually be missing:
Maven wrapper plugin(Mojo)
Maven Wrapper full POM

Generated project with gwt-maven-plugin : eclipse

I created a GWT project with
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.5.0
Imported the project in eclipse juno.
First error I get is this :
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:gwt-maven-
plugin:2.5.0:i18n (execution: default, phase: generate-sources)
In the pom file.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<runTarget>dashboard.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.farheap.jsi.dashboard.client.Messages</i18nMessagesBundle>
</configuration>
Also the code contains a GreetingServiceAsync that can not be found.
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
You have two options:
You can add special (non-trivial) org.eclipse.m2e:lifecycle-mapping plugin
configuration to your POM. See here: Why am I receiving a "Plugin execution not covered by lifecycle configuration with GWT" error?
Or mark this issue as to be ignored in Eclipse POM editor, and then call mvn gwt:i18n. You can create a handy short cut launcher for it. Eclipse remembers your decisions what to ignore, it stores it into .settings directory permanently for the project.
In course of typical development localization messages do not change often so the second option is usually more convenient and speeds up build.
This applies for most GWT plugin goals! Even GWT compilation is rarely necessary as DevMode works directly with Java code and not generated JavaScrips. So in practice, you have to call all the goals at least once on the beginning and then live weeks without them; basic Eclipse JDT compilation is sufficient.
If you later decide not to use GWT localization framework in your real app then you can remove goal i18n completely from POM. Calling goal i18n generates file {project}/target/generated-sources/gwt/my/code/client/Messages.java which is required by (vanilla) Sample.java.
Also the code contains a GreetingServiceAsync that can not be found.
Run the build mvn install from command line or Eclipse Run as -> Maven install menu.
In case of command line mvn gwt:generateAsync should be enough. This goal generates {project}\target\generated-sources\gwt\my\code\client\GreetingServiceAsync.java and that is what you missing. Eclipse did not do it for you automatically because it was blocked by previous issue of i18n not being covered by lifecycle configuration. So yes, issues you mention are correlated.

Anyone who actually got Tycho to work?

I'm trying to get Tycho working with m2eclipse. Problem is that all I find are outdated sites and old versions to download. I've found my way to http://github.com/sonatype/sonatype-tycho and downloaded the source. Problem is that the guide at https://docs.sonatype.org/display/TYCHO/BuildingTycho isn't of much help. When trying to build I run into an error message saying I'm using invalid syntax..... And there seems to be nowhere to ask for further guidance.
So are there anyone out there who actually got this working? Or got a better alternative for continuous integration / automatic build solution for eclipse plug-ins?
Tycho is a maven plugin, so you don't need to download it, just declare it in your pom.xml files.
See http://github.com/sonatype/sonatype-tycho/tree/master/tycho-its/projects/tycho001/ for details of a simple project.
This hint from Igor Fedorenko helped me to get it running:
https://issues.sonatype.org/browse/MNGECLIPSE-2140?focusedCommentId=115527&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_115527
If you are not pressed for time, I'd suggest to wait for the upcoming Update of m2eclipse, though. It was recently announced to follow shortly after Maven 3 release.
Robert, it does work for me as long as you don't try to build an Eclipse application. I have integrated it into CruiseControl and I am quite happy with building and testing plugins.
The main trick for me was to ignore all the P2/target stuff. I couldn't get it to work at all. Instead I call maven with an parameter that points to the Eclipse installation like this:
mvn -Dtycho.targetPlatform=C:\Programmer\eclipse
These are the necessary Plugin definitions:
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Current Tycho Version is 0.13.0.
I would like to build Eclipse Applications but need support myself for that.
I hope that helps.
Cheers,
Klaus
I had trouble with Tycho for a while until I realized it required Maven 3. If you're running Maven 2 it won't work.

Resources