8 Replies Latest reply on Oct 9, 2012 5:04 PM by dward

    Maven mojo proposal: setVersion

    dward

      Hey there kids!

       

      In experimenting with approaches to solve SWITCHYARD-733, I came up with a fairly simple solution.  Basically, create a new goal to our switchyard maven plugin, called "setVersion".  (The other one we have now is called "configure".)

       

      It would be invoked like this:

       

      mvn switchyard:setVersion -DoldVersion=0.6.0-SNAPSHOT -DnewVersion=0.6.0.Final
      

       

      Then the pom.xml for that project, and any of it's aggregated children, would have the following xml paths' values updated to 0.6.0.Final:

       

      project/version
      project/parent/version
      project/properties/switchyard.version
      

       

      I actually have most of it coded already, but now it just dumps the output to the console vs. overwriting the file.

       

      The mojo has an @phase of "validate" and @requiresDirectInvocation of "true", so that a project doesn't need to be built first for this to run, and you have to call it explicity (it would never be called during a normal build).

       

      Technically, I don't need the user to specify the oldVersion property, but figured it wouldn't be a bad idea just so they really know what they are doing.

       

      It's actually a pretty short and sweet approach.

       

      Thoughts?

        • 1. Re: Maven mojo proposal: setVersion
          dward

          Would also be easy for this to update the project/properties/version.distro property, as well as values inside installer.properties.

          • 2. Re: Maven mojo proposal: setVersion
            mageshbk

            Looks nice. But there seem to be another one on codehaus: http://mojo.codehaus.org/versions-maven-plugin/examples/set.html

             

            Does this not look much useful for our case? http://maven.apache.org/plugins/maven-release-plugin/examples/update-versions.html

            • 3. Re: Maven mojo proposal: setVersion
              kcbabo

              The maven approach looks promising.  It would be good to verify that the diff after the update only shows the version change vs. an entire file diff due to line endings / space vs. tab / etc.

              • 4. Re: Maven mojo proposal: setVersion
                dward

                I had already seen that plugin and played with it for quite some time.  It is very finicky, and doesn't always do what you think it's gonna do.  For example, updating the version is finding the newest version in a repository vs. setting it to what you want it to be.  In other cases, where you can explicity set it, it requires you to change your pom's to be "prepped" for use with the plugin. For example, it doesn't like you to use property placeholders for versions in dependencies you want to change. It would rather those be hardcoded and have it do the work of going through and changing them.  Finally, it only updates <version>s, it does not update <property>s that we define as version variables (ie: version.distro and switcyard.version), and won't update properties files (like our installer.properties).  We need something that does all of the above.

                • 5. Re: Maven mojo proposal: setVersion
                  dward

                  I thought about "the diff after the update" thing, and while it is possible to maintain all the crazy whitespace we have, I am of the opinion that I actually WANT it to homogenize the XML.  Our pom files right now are an atrocious mix of spaces (and various numbers of spaces) and tabs and newlines and what-have-you, all mixed in the same file.  If we sanitize the XML up front once (it can be done as part of the same pull request that introduces the plugin), then from then on the only changes would be the versions, unless of course someone introduced bad formatting at some point, in which case it would clean that up to.  I actually like this.  Sort of like a "checkstyle" for our poms.

                  • 6. Re: Maven mojo proposal: setVersion
                    kcbabo

                    I agree.  It's cool to establish a baseline formatting for all poms here and now, which will make diffs easier in the future.  That said, we should make sure the new formatting lines up with reasonable defaults (no tabs, proper indentation, etc.).  An easy way to test this is to run the script and then add a dependency to a pom to see if the formatting gets screwed up.

                    • 7. Re: Maven mojo proposal: setVersion
                      dward

                      Well the plugin actually uses our Configuration code to manipulate the DOM tree, so it can also use it's mechanism to pretty-print, which uses spaces, proper indents, etc.

                      • 8. Re: Maven mojo proposal: setVersion
                        dward

                        Pull requests submitted on the jira.  Here are the mojo instructions: Switchyard Maven Versioning Process