Search This Blog

Loading...

Things I wish Maven did....

The following are issues that I ran into using maven and would like to have them fixed or find a way around them.

  1. Version ranges not supported for parent artifacts (bug Link)

Maven 2 Commands that i use the most

Here is a quick list of commands i use all the time... there are a grep from my history

Basic Build
- mvn clean
- mvn clean install
- mvn clean install -Dmaven.test.skip (install without running tests)

Testing
- mvn clean test -Dtest=MyTest (runs a single test) you can use this for testing packages also
- mvn clean surefire-report:report ( run unit test and builds a surefire reports in target site dir. )

Testing Code coverage
- mvn clean cobertura:check ( run unit test and make sure we clear the check )
- mvn clean cobertura:cobertura

Building
- mvn -Dusername=gdawoud release:prepare (build step 1)
- mvn release:perform (build step 2)

Using Maven to test your code coverage

For a while i had mixed feelings about code coverage test and that has not changed but the number of lines in my projects has grown and we are under stress to deliver more features by the day I started to worry a bit about our test coverage of the code...

I have always used the cobertura-maven-plugin to generate reports of the code coverage but that is about it, ya cook look graphs that tell you how you are doing but never used it for more than that... This weekend is stated looking at my coverage and started to add checks to each project to make sure we can't build if we fail below a set % of code coverage.

That was good and bad... i played with a lot of the different settings that you can check and ended up using only total line rate (see blow) where the system make sure we run over % of the total lines in the project and if we don't hit the build fails...

A few things to note:

  • I was suppressed to learn that cobertura does not work well with static or enum classes and calls.
  • You should exclude any auto generated code from your coverage check
  • A new fill called cobertura.ser will show up on desk.. make sure you add it to the .cvsingore or source control ignore file since if that file is checked in it will break everything
  • Check out Java: Measure Test Coverage with Cobertura
  • You can use "-Dmaven.test.skip" when haltOnFailure is set to true

Anyway here is a sample of how i use the plugin

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>cobertura-maven-plugin</artifactId>
 <executions>
  <execution>
   <goals>
    <goal>clean</goal>
    <goal>check</goal>
   </goals>
  </execution>
 </executions>
 <configuration>
  <check>
   <haltOnFailure>true</haltOnFailure>
   <totalLineRate>65</totalLineRate>
  </check>
  <instrumentation>
   <excludes>
    <exclude>com/company/autogen/**/*.class</exclude>
   </excludes>
  </instrumentation>
 </configuration>
</plugin>

Maven 2 - WSDL TO Java using Jaxb

Step 1:
Download the wsdls and put them in a dir i use "src/main/wsdl", this must match schemaDirectory
Step 2:
Add the following to the build pom.xml

<build>
   <plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <executions>
        <execution>
                <id>ws-source-gen</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaDirectory>src/main/wsdl</schemaDirectory>
                    <generateDirectory>src/main/autogen</generateDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
....
</build>

Step 3:
Add the autogen dir to the resources

        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/autogen</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

Step 4:
I tent do run mvn test to gen the source and run the unit test with the genrated sources

NOTES:
- Don't check in autogen into source countral
After trial and error i learned not to check the auto gen code since you contal the changes to it by checked in the wsdl.

- Exclude autogen code from code covrage
using org.codehaus.mojo to do code covrage i tend to add the following plugin and exclude the auto gencode... so that the reports are clean

<plugin>
 <groupId>org.codehaus.mojo</groupId>
  <artifactId>cobertura-maven-plugin</artifactId>
 <executions>
  <execution>
       <goals>
       <goal>clean</goal>
       </goals>
  </execution>
  </executions>
  <configuration>
  <instrumentation>
       <excludes>
       <exclude>com/company/autogen/**/*.class</exclude>
       </excludes>
  </instrumentation>
  </configuration>
</plugin>

Maven and /xml/internal/security/Init

I have been running TeamCity Enterprise Version 3.1.1 for my CI with Maven and been getting the following errors

java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/security/Init

i was able to fix the this error by adding the following to the pom file...

<dependency>
 <groupId>com.sun.org.apache.xml.security</groupId>
 <artifactId>xmlsec</artifactId>
 <version>2.0</version>
 <scope>test</scope>
</dependency>

If you are having this issue in tomcat then add the above dependency to your pom less the scope like the following

   <dependency>
        <groupId>com.sun.org.apache.xml.security</groupId>
        <artifactId>xmlsec</artifactId>
        <version>2.0</version>
   </dependency>

Use Maven to precompile your JSP

By adding the following plugins to your pom.xml you will be able to precompile your JSPs and have them included in your war file.

1. part is to include the jspc-mavne-plugin which will complile your jsp into java classess. Make sure to configure the java vesion for the jsp classes.


org.codehaus.mojo
jspc-maven-plugin


jspc

compile


1.5
1.5






2. Update the maven-war-plugin to use the a new web.xml created by the plugin above

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${basedir}/target/jspweb.xml</webXml>
</configuration>
</plugin>

3. you don't have to add anything to you web.xml the new jspweb.xml takes the existing web.xml and addess to it all the needed servlet mapping

<servlet>
<servlet-name>jsp.navs.jsp.footer_jsp</servlet-name>
<servlet-class>jsp.navs.jsp.footer_jsp</servlet-class>
</servlet>

MouseFeed Eclipse Plugin

Learn Eclipse Key Shotcuts using this plugin and be more productive/

http://www.mousefeed.com/

Build systems and Maven 2...

Build systems and Maven 2...

Every project I worked on needed a build system and most of the time it has been a big ugly ant build system which once written no one wants to own it or say they worked on it. Over the last few year i stared using maven at work. At that point of time Maven 2 was the new build system that should solve every build system nightmare. At first it was hard using maven, things that our old build system maven could not due out of the box. But over the years i learned to love and hate maven with the help of a few plugins.

In this blog i list and try to show how i used different Maven 2 plugins to make my new application system the best it can be with a maven build system.

Topics

PlugIns
Web Service WSDL to Java AutoGen

As you can tell, i use a lot of maven and a lot of maven plugins to make my build system simple and easy for me to release the applications and also this will server a simple get up and go for any new developer that joins my team. I'll be creating a blog page for each topic/plugin and tell you how i use it and who make it a pain in the ass. So if i you are looking for info on a plugin and it is not listed yet... leave a comment and i'll get back to you ASAP.

Enjoy
George

Blog more....

This weekend I'm attending the No Fluff Just Stuff conference and Day 1 ended with a great keynote speech by Jared Richardson and one thing I'm planing to do is post more technical blogs ... so watch out they may be good, they may sux... but i'll posting more...

Add Coptic Calendar to Outlook

I got this via email a few times... The following link has simple instructions are found at

http://www.suscopts.org/stmaryhouston/framePage.html?/stmaryhouston/church/coptic_outlook.html