Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

maven-enforcer-plugin

Posted on by Kim

To ensure dependencies

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0-M3</version>
                <executions>
                    <execution>
                        <id>enforcer</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <dependencyConvergence/>
                                <requireReleaseDeps>
                                    <onlyWhenRelease>true</onlyWhenRelease>
                                </requireReleaseDeps>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Auto deploy on WAS on localhost

Posted on by Kim


<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <executable>${env.WAS_HOME}\bin\wsadmin.bat</executable>
        <workingDirectory>${commons.test.dir}</workingDirectory>
        <commandlineArgs>-host localhost -f autodeploy/deployall.jacl -p "${basedir}"/../CamelProperties.txt </commandlineArgs>
    </configuration>
</plugin>

Sample Gradle, Groovy Project on IntelliJ

Posted on by Kim

Change the build.gradle Add mavenLocal and right plugins...

See: The Groovy Plugin

group 'as.moes.gradletest'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'jetty'
apply plugin: 'war'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'

    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Switch to google mirror

Posted on by Kim

Change ~/.m2/settings.xml


  
    
      google-maven-central
      Google Maven Central
      https://maven-central.storage.googleapis.com
      central
    
  

Thanks to Matt Raible, see: Google's Mirror of Maven Central 25% Faster

Groovy Spock test form Java Maven project

Posted on by Kim

Setup in maven


    
        junit
        junit
        4.12
        test
    
    
        org.spockframework
        spock-core
        1.0-groovy-2.4
        test
    
    
        org.codehaus.groovy
        groovy-all
        2.4.4
        test
    
    
        com.athaydes
        spock-reports
        1.2.7
        test
    



    org.apache.maven.plugins
    maven-compiler-plugin
    
        UTF-8
        1.8
        ${jdk.target.version}
    


    org.codehaus.gmavenplus
    gmavenplus-plugin
    1.5
    
        
            
                addTestSources
                testCompile
            
        
    


    org.apache.maven.plugins
    maven-surefire-plugin
    2.18.1
    
        
            **/*Test.java
            **/*Spec.java
        
    

See : Writing Unit Tests With Spock Framework: Creating a Maven Project Thanks to Petri Kainulainen

Simple fix to missing tools.jar in JDK on Mac OS X

Posted on by Kim

THANKS to David B. Knickerbocker for this

Simple fix to missing tools.jar in JDK on Mac OS X

Today I ran into a situation where a 3rd-party pom.xml had a dependency on tools.jar.  I'm stuck using Java 6, due to project requirements, which means I have to use the Apple supplied JDK.  The problem is Apple bundled all the classes normally found in tools.tar into classes.jar.  Since I couldn't modify the pom file, I simply creating a symbolic link to classes.jar.

 $> sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/tools.jar  
 $> sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/lib  

Maven properties

Posted on by Kim

maven.build.timestamp
project.build.sourceDirectory

project.build.scriptSourceDirectory
project.build.testSourceDirectory
project.build.outputDirectory
project.build.testOutputDirectory
project.build.directory



Note: In Maven 3.0, all pom.* properties are deprecated. Use project.* instead!

Built-in properties

  • ${basedir} represents the directory containing pom.xml
  • ${version} equivalent to ${project.version} (deprecated: ${pom.version})

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix. This list is just an example of some commonly used elements. (deprecated: {pom.} prefix)
  • ${project.build.directory} results in the path to your "target" directory, this is the same as ${pom.project.build.directory}
  • ${project.build.outputDirectory} results in the path to your "target/classes" directory
  • ${project.name}refers to the name of the project (deprecated: ${pom.name} ).
  • ${project.version} refers to the version of the project (deprecated: or ${pom.version}).
  • ${project.build.finalName} refers to the final name of the file created when the built project is packaged

Local user settings

Similarly, values in the user's settings.xml can be referenced using property names with settings. prefix.
  • ${settings.localRepository} refers to the path of the user's local repository

Environment variables

Environment variables can be referenced using the env prefix
  • ${env.M2_HOME} returns the Maven2 installation path.
  • ${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
    ${java.home}../bin/java.exe

Java system properties

All Java System Properties defined by the JVM.


Source: 

MavenPropertiesGuide
Maven properties

How to make a Maven plugin

Posted on by Kim

// To make project

mvn archetype:generate
--
Choose number 12
--
Define value for groupId: : as.moes.plugin    
Define value for artifactId: : testplugin
Define value for version:  1.0-SNAPSHOT: : 
Define value for package:  as.moes.plugin: : 
Confirm properties configuration:
groupId: as.moes.plugin
artifactId: testplugin
version: 1.0-SNAPSHOT
package: as.moes.plugin
// To change
cd testplugin
mvn eclipse:eclipse
// To deploy
mvn testplugin:touch
// Test with
<build>
    <plugins>
        <plugin>
            <groupid>as.moes.plugin</groupId>
            <artifactid>testplugin</artifactId>
            <version>1.0-SNAPSHOT</version>
            <configuration>
                <outputdirectory>/home/kim/tmp</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

Simple method to create a new project in maven

Posted on by Kim

mvn archetype:generate

Link: Maven Archetype Plugin

Create manifest and scope in Maven

Posted on by Kim

<dependency>
     <groupId>commons-betwixt</groupId>
     <artifactId>commons-betwixt</artifactId>
     <version>0.8</version>
     <scope>provided</scope>
     <!-- excluded from manifest classpath, and excluded from WEB-INF/lib -->
</dependency>


<dependency>
     <groupId>commons-betwixt</groupId>
     <artifactId>commons-betwixt</artifactId>
     <version>0.8</version>
     <!-- goes in manifest classpath, AND included in WEB-INF/lib -->
</dependency>


<dependency>
     <groupId>commons-betwixt</groupId>
     <artifactId>commons-betwixt</artifactId>
     <version>0.8</version>
     <optional>true</optional>
     <!-- goes in manifest classpath, but not included in WEB-INF/lib -->
</dependency>

Create new web project for eclipse with maven (archetype)

Posted on by Kim

E.g.

mvn archetype:create -DgroupId=as.moes.mmsinbox -DartifactId=mmsinbox -DarchetypeArtifactId=maven-archetype-webapp
mvn eclipse:eclipse

Add 3. part jars to maven project

Posted on by Kim

Nice way to add 3. part jars to your maven project is to install them to the local repository.

Put jars i ./lib and add a ant-build file to the project.

Content of setup.xml


<project name="MMS_provisioning" basedir="." default="maven">
<property name="lib.dir" location="${basedir}/lib" />

<target name="maven" description="Install jars to local repository">
<exec command="mvn" vmlauncher="false" failonerror="true">
<arg line="install:install-file -Dfile=${lib.dir}/ojdbc14.jar
-DgroupId=com.oracle -DartifactId=ojdbc14
-Dversion=9.0.2.0.0 -Dpackaging=jar" />
</exec>
<exec command="mvn" vmlauncher="false" failonerror="true">
<arg line="install:install-file -Dfile=${lib.dir}/profiler.jar
-DgroupId=com.nokia -DartifactId=profiler
-Dversion=1.0.0 -Dpackaging=jar" />
</exec>
</target>
</project>