Tuesday, November 8, 2011

Maven - mavenize project and recipes

Links and commands used by the authors:
http://i-proving.com/2007/03/29/Maven-Recipes/

http://i-proving.com/2007/04/27/How-to-Mavenize-an-Existing-Eclipse-Project/ :
Insure that your M2_REPO variable is properly defined
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
mvn eclipse:eclipse -DdownloadSources=true

http://i-proving.com/2009/11/03/creating-a-maven-project-and-adding-it-to-subversion/ :
mvn archetype:create -DgroupId=[packageName] -DartifactId=[projectName]
mvn eclipse:eclipse -DdownloadSources.
For integration with Hudson, some nodes should be added to the pom.xml
 1. parent 
 2. distributionManagement 
 3. scm
Project under an existing project:
Using the command line, enter the following in the root of the parent project
mvn archetype:create -DgroupId=[packageName] -DartifactId=[projectName]
svn add 'projectName'
svn commit [projectName] pom.xml
mvn eclipse:eclipse -DdownloadSources

http://i-proving.com/2007/05/10/How-to-Determine-the-Maven-dependency-to-use-for-a-jar/ :
$ md5sum commons-collections.jar
$ openssl dgst -md5 commons-collections.jar
$ openssl dgst -sha commons-collections.jar
mvn deploy:deploy-file -Dfile=<the file to deploy> \
   -Durl=<url to your repository> \
   -Dpackaging=jar \
   -DrepositoryId=<the repositoryID> \
   -DpomFile=<path to your pom.xml file>

http://i-proving.com/2007/03/29/Split-Your-Project-Into-Sub-Projects/ :
+-- workspace/
    +-- myproject/
    |    +-- pom.xml    --IMP: please refer link for contents. Note <packaging>pom</packaging>
    +-- subproject-1/
    |    +-- pom.xml
    +-- subproject-2/
        +-- pom.xml
The  myproject pom makes myproject your "one stop shopping" location for running mvn goals such as install or release or eclipse:eclipse
If subproject-1 pom has
<groupId>ca.intelliware</groupId>
  <artifactId>subproject-1</artifactId>
  <version>1.0-SNAPSHOT</version>
and if subproject-2 consumes subproject-1 as a dependency
then
<dependencies>
    <dependency>
        <groupId>ca.intelliware</groupId>
        <artifactId>subproject-1</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
eclipse:eclipse goal behaviour:
If dependency.SNAPSHOT: subproject-2 should reference the Eclipse project for subproject-1 as a project dependency in its Java build path
else if dependency.RELEASE: Eclipse project that gets generated by the eclipse:eclipse will simply refer to the released version of the JAR in your M2_REPO repository
1. mvn archetype:create -DartifactId=myNewProject -DgroupId=ca.intelliware
2. cd myNewProject 
3. mvn archetype:create -DartifactId=myNewSubProject-i -DgroupId=ca.intelliware
4. cd ..
5. mv myNewProject/myNewSubProject-i ./myNewSubProject-i
6. Edit myNewProject.POM
<modules>
        <module>../myNewSubProject-1</module>
        <module>../myNewSubProject-2</module>
</modules>
7. mvn -DdownloadSources=true eclipse:eclipse
SPLITTING PROJECT: foobar->{foo,bar}
1. Rename foobar as foo
2. mvn archetype:create -DartifactId=foobar -DgroupId=ca.intelliware

Edit foobar.POM.packaging to "pom"
3. cd foobar
4. mvn archetype:create -DartifactId=bar -DgroupId=ca.intelliware
5. cd ..
6. mv foobar/foo ./foo
7. Edit foo.POM.artifactId to foo
8. Copy bar.POM.parent to foo.POM.parent
9. Edit foobar.POM

<modules>
    <module>../foo</module>
    <module>../bar</module>
</modules>
10. Move code you want to split from foo to bar
11. mvn eclipse:eclipse
Thats it for now!!!

C:\>mvn install:install-file -Dfile=utils.jar -DgroupId=com.zparacha.example -DartifactId=utils -Dversion=1.0 -Dpackaging=jar

2 comments:

  1. Just a quick update, the i-proving.cas should be http://i-proving.com/ 's:)

    ReplyDelete