create POM with junit 4 - maven-3

I use Maven 3.0.4 and want to have junit 4 by default.
My projects are created with the command :
$>mvn archetype:create -DgroupId=my.group.id -DartifactId=myArtifactId -DpackageName=my.package.name
This puts a depency to junit version 3.8.1 in the created pom.xml, dispite the fact that verion 4.8.1 is already present.
There are no dependencies to junit in my global settings.xml, and I haven't a local .m2/repository/settings.xml. I don't want to remove the old version 3.8.1., but want that all new projects are created with version 4.8.1
Can I do this in my settings.xml (global or local does not matter)? And if so what is the correct syntax?

A couple things:
archetype:create is deprecated by archetype:generate; please use generate, it's interchangeable with create in your example.
As for a solution, I'd say the simplest thing to do is generate your project, edit the pom to have the correct junit version; and then from within your project run:
mvn archetype:create-from-project
Which will create an archetype based on your modifications, you simply need to install this with:
cd target/generated-sources/archetype/
mvn install
Now you can create new maven projects with this new archetype as you like with:
mvn archetype:generate -DgroupId=my.group.id -DartifactId=newArtifact -DpackageName=my.package.name -DarchetypeArtifactId=myArtifactId-archetype -DarchetypeGroupId=my.group.id
Hopefully this helps.

Related

Equivalent to maven-install command in Grails 3

I have begun the journey of migrating my Grails apps to version 3.
I have a number of plugins that I with Grails 2 have installed to the local maven repository with the maven-install command available with the release plugin. They have then been easily accessible to my main project for import.
As far as I can see the release plugin does not exist for Grails 3. My question is, should I try to migrate the release plugin or is there some other, better way, in Grails 3?
If you have
apply plugin: 'maven-publish'
and the two apply from: 'https://raw.githubusercontent.com/... lines from the build.gradle file that's created for you when you create a Grails 3 plugin you can run
./gradlew install
to do the same thing as the maven-install script.

Which version of jdk can i use for building a maven project?

I'm going to build a maven project for the first time. I downloaded maven- 3.1.1 and I want to know if I can use jdk 1.7.0._05. If there is any other version that I need to use, please do specify.
Thanks :)
As far as I know there isn't any version that you are forced to use to build Maven project. You can simply run:
mvn -version
to see what version is used currently by Maven. This version should match the JDK you have set as JAVA_HOME, so in case if you want to change it, simply change your JAVA_HOME to different directory.
Have a look at System Requirements noted at the download page:
JDK: 1.5 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's)

How to make Grails get latest local jars from Maven repository?

In my Maven repo (.m2). there is one my local jar like sub_app-0.1.jar.
I have same copy of the it in ivy-cache.
I run maven install on sub_app then new sub_app-0.1.jar file created.
After, I run grails clean and it not getting my new sub_app-0.1.jar from .m2.
But, if I remove (delete) sub_app-0.1.jar file from ivy-cache and run the grails clean then it is getting new sub_app-0.1.jar file into ivy-cache.
If I change the version in sub-app pom and grails pom and Grails is taking latest one. install again it not taking.
I tried by adding SNAPSHOT to sup-app jar even. Same result, first time it is taking, after not.
ie. Grails considering only jar name and version in ivy-cache, if having - it not take. If not having - it taking from .m2.
But it not considering new/old build.
How can I get the same behavior (step 5) in step 4 also?
UPDATED
You can try adding changing=true to your dependency in the BuildConfig.groovy, as specified in the Grails Guide
compile ('YOUR_GROUP_ID:YOUR_SUB_AP:0.1') {
changing = true
}
Not sure if this is the same problem as you, but I use Spring Source Tool Suite (STS) with a 'grails' project having a dependency on an 'interfaces' project (which just contains interfaces, beans, pojos, etc).
If I run a maven install on interfaces in STS, then maven correctly updated with latest jar (I use '-1.0-SNAPSHOT' as my version number).
If I then run a grails clean on my 'grails' project in STS, Grails correctly identifies the change of the interfaces jar (I have {changing=true} in BuildConfig.groovy), downloads the pom, but fails to download the jar as it cannot delete the jar from the ivy-cache. Looks like STS has a handle on the ivy-cache which prevents this.
As I inherited this project from another developer who informed me it was a bug/feature of Grails and/or STS, I've bowed to his knowledge and workaround this by either:
maven package instead of install on 'interfaces' then copy the latest jar to the ivy-cache. It seems STS will let me replace the contents of the jar. Then grails clean uses the latest jar from ivy-cache (no attempt to download from maven).
maven install on 'interfaces', close down STS, delete jar from ivy-cache, re-open STS, grails clean which downloads latest jar from maven.
Both workarounds as a pain, so I'd be interested if anyone has any ideas?
Grails not supports to get latest of same (group-id, artifact-id, version) jar even SNAPSHOT jar also.
Solutions:
Every-time, delete the sub-app-version.jar from ivy-cache. or
Every-time, change the version to next value(should be greater than current value) of the sub-app jar in pom.xml.
4 Configuration - Reference Documentation
Please read:
4.7.6 Snapshots and Other Changing Dependencies

Filter archetypes in Maven command line with archetype:generate

When trying to generate a Maven project from an archetype (using mvn archetype:generate), the command returns a lots of archetypes.
Is there a way to filter archetypes given a word (contained in groupId or artifactId)?
I know you can actually create a project with a specific archetype, with arguments like -DgroupID=org.domain -DartifactId=sample, but it's not what I'm looking for.
Ok. A bug as been filed and should be resolved in Maven archetype plugin version 2.1.
Edit:
Bug is solved in maven-archetype-plugin version 2.1. Documentation is ready.
mvn archetype:generate -Dfilter=org.apache:struts
For a groupId containing org.apache AND an artifactId containing struts

How to build from my checkout directory ... with a twist

We're using Maven 3 with Git as our SCM system. We are using the latest version of the scm plugin (1.5). Our project is in Grails 1.2.1 (Java 1.5). The question is, how do I run a single command to generate a WAR file after doing a checkout from our repo?
This question seems complicated by the fact that we're using the a Grails project (and hence the maven-grails plugin, version 1.3.4). Grateful for any info you have, - Dave
I'm assuming that the command line below below wont work for you because of your requirement to use maven.
grails <environment> war
You can generate a pom.xml for your existing grails project with the following command. This can be a useful starting point.
mvn grails:create-pom
More documentation about grails's maven integration can be found here:
http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html#4.5%20Ant%20and%20Maven

Resources