Java7
Posts tagged maven
Integrate project specific checkstyle into your Maven build goals :)
Nov 7th
Firstly, in almost every development project that has not passed its prime, everyone adheres to some kind of coding checklist. But overtime (especially during the maintenance and support phase) the topic becomes like a lip service, in most scenarios no one would govern it, everyone cuts some slack and the source code becomes an expensive garbage.
Or worse of all, someone comes up with some coding checklist full of anti-patterns. :)
Checkstyle is a very mature code checking library developed some time ago for this purpose.
Today we are going to show you how to integrate checkstyle into your Maven build. I use Maven for project development management but you can do equally well with Ant or other build tools. (Just to note that Maven is not just a build tool! :P)
Assumptions
1. You are using Maven
2. You have installed CheckStyle plugin in your Eclipse IDE (Fine if you are not using Eclipse, you may run parts of the example off from the command line $mvn)
3. You are using Eclipse IDE@@ (Again, you don’t have to although most of example here will illustrate using Eclipse IDE)
4. By reading this post we have actually assumed you are an advanced and intelligent developer..
Steps
1. Have your external Checkstyle configuration file in hand. See http://java.sg/allow-project-specific-settings-in-checkstyle-plugin/
2. Locate and open your pom.xml (Project Object Model)
3. Insert the following code snippet into your plugins.
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<configuration>
<configLocation>C:\checkstyle-javasg.xml</configLocation>
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
Substitute configLocation with your own configuration file. In addition, this value may be a URL, File, or build classpath resource reference.
4. Add the checkstyle:check goal into your Maven task.
Go to Project > Run Configurations
Browse to your Maven build configuration, add “checkstyle:check” to your goals.
Apply and run.
Note: If you are running this off the command line, this would suffice:
$mvn checkstyle:check clean package
Checkstyle stops me from continuing with the violation:
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building hms-web 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-checkstyle-plugin:2.8:check (default-cli) @ hms-web --- [INFO] [INFO] There are 1 checkstyle errors. [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.529s [INFO] Finished at: Mon Nov 07 14:53:51 SGT 2011 [INFO] Final Memory: 19M/64M [INFO] ------------------------------------------------------------------------
Now, your codes are automatically checked by checkstyle. Checkstyle fails with an error and will not allow Maven to continue with the rest of the goals until you have rectified the Checkstyle violations. :)
In a later tutorial, i will post how Checkstyle may be integrated into Jenkins (Fork of Hudson).
Reference
Maven Cargo Error: Artifact [xx:xx:war] is not a dependency of the project.
Nov 6th
You run a Maven task and it fails with the message “Artifact [xx:xx:war] is not a dependency of the project.”.
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.1.3:deploy (default-cli) on project hms-web: Artifact [sg.java:hms-web:war] is not a dependency of the project. -> [Help 1]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
It tells you to get more help with a link reference that i did not find much helpful.
This error is surfacing because you have specified in your Maven task to deploy the WAR with cargo:deploy.
Cargo could not find the war!
Rectification
Check that your project coordinates tally with what you have specified in the Cargo plugin, specifically the groupId and artifactId.
Making sure the groupId and artifactId project coordinates tally with what is specified in Cargo plugin solves the problem.
Take note of the groupId and artifactId project coordinates specified.
Check that the groupId and artifactId project coordinates tally with what you have specified inside the Cargo plugin.
If the groupId and artifactId project coordinates do not tally, the Cargo plugin will stop with an error.
Mistakes like this are hard to pin point especially if you have transferred this pom.xml from another project which appeared to have worked perfectly. It helps a little if you turn on the DEBUG logging level from the Eclipse preference.
This would have been what you will see with DEBUG logging level:
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.1.3:deploy (default-cli) on project hms-web: Artifact [sg.java:hms-web:war] is not a dependency of the project. -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.1.3:deploy (default-cli) on project hms-web: Artifact [sg.java:hms-web:war] is not a dependency of the project. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:60) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:354) Caused by: org.apache.maven.plugin.MojoExecutionException: Artifact [sg.java:hms-web:war] is not a dependency of the project. at org.codehaus.cargo.maven2.configuration.AbstractDependency.findArtifactLocation(AbstractDependency.java:182) at org.codehaus.cargo.maven2.configuration.Deployable.computeLocation(Deployable.java:303) at org.codehaus.cargo.maven2.configuration.Deployable.createDeployable(Deployable.java:177) at org.codehaus.cargo.maven2.AbstractDeployerMojo.performDeployerActionOnAllDeployables(AbstractDeployerMojo.java:187) at org.codehaus.cargo.maven2.AbstractDeployerMojo.doExecute(AbstractDeployerMojo.java:103) at org.codehaus.cargo.maven2.AbstractCargoMojo.execute(AbstractCargoMojo.java:279) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more
Using Maven behind an office proxy
Sep 3rd
Right! The same thing you did in home didn’t work for your office setup (though you couldn’t not blame that it could be due to your office PC setup not being blazingly faster than your home PC, but that is not the “root cause” 90% of the time =p)
Chances are, when you are in the office, you are behind a proxy, and whether you are aware of changes that have been made to your internet browser by your network or PC administrator, you need to configure Maven accordingly too, for Maven to work in a snap.
Check your proxy settings
Here is how you can verify your proxy settings, information which you would need for putting it into Maven’s settings.xml.
Go to Internet Explorer (Sorry i that am using IE 6 for this demonstration, this is really for the benefit of those who have survived the big bang haha ><) > Tools > Internet Options > Connections > LAN Settings.
Take note of the host (singproxy.as) and the port number (80), you will need this for later.
Change your Maven proxy settings
Go to your Maven home directory, locate the file settings.xml in the conf directory.
* By modifying this file directory, we are changing the settings globally for users of this local machine, which is probably 99% of time what you would like to do, however if not, you can make changes to this at a user level.
Open up settings.xml, locate and edit the proxy settings. Using the host and port number obtained from the above step, edit, save, and close the descriptor (settings.xml).
<proxies>
<proxy>
<id>my office proxy</id>
<active>true</active>
<protocol>http</protocol>
<username>chinboon</username>
<password>password</password>
<host>singproxy.as</host>
<port>80</port>
<nonProxyHosts>*.gij|*.omnia|*.as|10.*|*.local|*.quest.com|*.toadsoft.com</nonProxyHosts>
</proxy>
</proxies>
Verify changes made
In the last step, you could verify the changes have been made successfully by going back to do what was initially stopping you, these errors should go away. For my situation where because of the proxy settings, Maven was unable to down the index from the public repository, and this problem went away for me.
Maven is able to download and index my local m2 repository. :)
Still having problems?
If you are using Eclipse, then chances are that you are using the embedded Maven installation managed by your plugin exclusively, and it can become troublesome to maintain.
Check if you are using an embedded Maven installation, add the external installation that you have installed by yourself, i.e. the one at C:/maven/xxxx. Verify that the settings.xml is the one you have edited in the above steps.
:) Have lots of fun playing with Maven!
VISDK Maven pom.xml Dependency
Jun 19th
There is some confusion over vijava and the VI SDK API provided directly by VMware. Which in any case, the VISDK is a higher level abstraction of the library (VI SDK), former provided by an enthusiast contributor, the later by VMware, vijava is now maintained by an open source community. =)
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>vijava</artifactId>
<version>2120100824</version>
</dependency>
Maven Repository Search
http://mvnrepository.com/artifact/org.jvnet.hudson/vijava/2120100824
vijava Homepage (Note that Google places it 4th in the search for “VISDK” :/ I’m not surprised)
http://vijava.sourceforge.net/
Official VI SDK Homepage (provided directly by VMware)
http://www.vmware.com/support/developer/vc-sdk/
History
June 26, 2011 Improved readability, grammar.
AspectJ Maven pom.xml Dependency
Jun 19th









