2

I have an archetype that we use to create new projects. At the point of project creation (i.e. when someone executes mvn archetype:generate) I want to pin some of the dependencies to RELEASE version available at that time (I strongly oppose putting <version>RELEASE</version> in POM file).

Is there a way I can make archetype to resolve RELEASE version and pin that for some of the libraries.

Only way I solve this problem right now is by releasing new version of archetype every time some of the core libraries are released and then hard coding versions of those in the archetype-resources/pom.xml

I did see couple of similar questions but none of the solutions for those work for me.

As I already mentioned, that I want to pin the latest release version available at the time of creating project from archetype. Using `RELEASE means that I can not recreate binaries from same source code as I will end up fetching a different version of dependency.

Let me explain with concrete example.

  • I have an archetype with maven co-ordinate com.my-company:my-awesome-framework:1.0.
  • I have a library with maven co-ordinates com.my-company:core-lib:1.0.
  • Developer-1 runs command mvn archeype:generate my-awesome-framework. He fills in required details and creates project called service-foo. service -foo has dependency core-lib and since.
  • We add more features to core-lib and release version 2.0
  • Developer-1 build service-foo it still builds with core-lib version 1.0. (since he hasn't changed the version the project's POM file. Had I used <version>RELEASE<version> for 'core-lib, this timeservice-foowould have built with version2.0of thecore-lib`)
  • Devloper-2 runs mvn archetype:generate my-awesome-framework. He fills out required fields and creates a service called service-bar. Now this time since core-lib version 2.0. Note that I did not modify my-awesome-archetype to update version for core-lib inside archetype-resources\pom.xml

I hope this clarifies my use case

Pushkar
  • 541
  • 4
  • 18
  • Possible duplicate of [How do I tell Maven to use the latest version of a dependency?](http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency) – A_Di-Matteo Jan 07 '16 at 09:03
  • I disagree, this is a uniquely different question -- RELEASE will always pull in the latest release, even after the project is generated. He wants to pin the version *at generation time*. – Steven Schlansker Jul 22 '16 at 20:40

1 Answers1

0

I solved this using archetype-post-generate.groovy, script. Maven archetype plugin executes that (if available) after the project has been created. There one can use Maven versions plugin to update to the latest releases.

Here is an example how you can update both versions in properties and in parent project (in Spring Boot in this case):

dir = new File(new File(request.outputDirectory), request.artifactId)

def run(String cmd) {
    def process = cmd.execute(null, dir)
    process.waitForProcessOutput((Appendable)System.out, System.err)
    if (process.exitValue() != 0) {
        throw new Exception("Command '$cmd' exited with code: ${process.exitValue()}")
    }
}

run("echo 'Updating to latest Vaadin version...'")
run("mvn versions:update-properties")

run("echo 'Updating to latest Spring Boot version...'")
run("mvn versions:update-parent")

The downside is that Eclipse don't seem to execute that script, but in other major IDEs and command line this work just fine.

The groovy script form my Vaadin + Spring Boot archetype in GitHub.

mstahv
  • 1,784
  • 9
  • 7