1

I have Java projects compiled with maven. Each project has its own POM which looks like the following :

<project ...>
    <groupId>group.id</groupId>
    <artifactId>scripts</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    ...
    <dependencies>
          <dependency>
              <groupId>global</groupId>
              <artifactId>common</artifactId>
              <version>10.2.3-SNAPSHOT</version>
          </dependency>
    </dependencies>
    ...
</project>

SNAPSHOT as a RELEASE

If I do a mvn install, it will compile/install it the first time I execute the command. Next times, it won't install it. It seams that maven consider it as a RELEASE, weither it is a SNAPSHOT. I can see that in the timestamp included into the installed package. if I don't change the version number, the timestamp does not change either.

I believe I miss a maven configuration but this impacts a lot our development as we're force to change the projects versions (and their dependancies) for every test deployment.

Notes : I'm using maven 3.3.3. It looks like I had not this behavior in 3.1.0 (I'm not 100% sure of the old version. Very old anyway). Maven is coupled with Nexus. Maybe the issue comes from it and I'm focussing on the wrong horse.

Thank you for the hints.

Edit : the question is : How can I get maven installing SNAPSHOTs everytime instead of the first time only like a RELEASE ?

EDIT SOLVED

We've always done mvn install to compile and install the sources. For some reason, we haven't used the mvn clean command. The correct maven command to recompile all the sources is mvn clean install.

Thank you @VinayVeluri

Johny E
  • 25
  • 2
  • 6
  • There's a lot of good information here, but what's your question? – byxor Sep 07 '16 at 08:51
  • Possible duplicate of http://stackoverflow.com/questions/2358965/maven-automatic-snapshot-update. Answer `mvn -U, --update-snapshots Forces a check for updated releases and snapshots on remote repository` Is might help you in this case – Xantier Sep 07 '16 at 08:52
  • Where are you looking this ? `target` folder or `.m2-> repo`? Install releases to repo, but it does that everytime – Vinay Veluri Sep 07 '16 at 08:54
  • 1
    @BrandonIbbotson Sorry, the question is : How can I get maven installing real SNAPSHOT everytime ? – Johny E Sep 07 '16 at 09:21
  • @VinayVeluri Both of them. `Install` releases to repo indeed, but in my case it release the first compiled sources. For instance, I've compiled a -SNAPSHOT this morning at 9am. If I redo an `mvn install` now with the same project version, the files into the target folder and the maven repo will be the ones from 9am still. For me, if it's a SNAPSHOT, it should replace the sources. Am I right ? Right now I'm forced to add a SNAPSHOT-01 / S...-02 / etc. for every `install`. I believe this is not the normal behavior of a snapshots version. Thanks – Johny E Sep 07 '16 at 09:48
  • If you run mvn install, do you get a BUILD SUCCESS? Does it give you some kind of warning or say something where the resulting jars are installed? – J Fabian Meier Sep 07 '16 at 10:00
  • Never heard of such behaviour. Try to run the build with the -X (debug) switch and have a detailed look at the install plugin execution. – FrVaBe Sep 07 '16 at 10:02
  • Try `clean` the target and regenerate the artifacts. How about the build status ? – Vinay Veluri Sep 07 '16 at 11:09

1 Answers1

0

If versions are needed for the code changes, Please version yourself for the code base, though it is cumbersome gives the idea of versioning.

If it has to automatic regarding the snapshots update, then use

mvn -u clean install

Once added, this command line arg forces Maven to check all snapshots in a remote repository and update your local repository if it’s out of date.

source

Vinay Veluri
  • 6,671
  • 5
  • 32
  • 56
  • 1
    In the meantime, we've digged into the issue and we have found the exact same solution which is pretty simple. This is amazing how you look stupid when something so simple solve it... We have never done any `clean` before `install`, then maven wasn't re-compiling the sources. Thank you for the answer. – Johny E Sep 07 '16 at 13:01