1

This is kind of a ridiculous thing to do, but for some back-story we develop a number of java packages that become part of a large, unwieldy system. We have no control over the builds for this large system. We just check code into a subversion repo and jenkins takes over from there. The problem we've had in the past is that we have no indication that the code we checked in is actually running in any of the test or production environments. The group doing these builds is incompetent at best and can't seem to provide any real information. This continuous build environment does not lend itself to us changing minor version numbers every time a code change is made. And there are about a dozen packages so I'd prefer not to have to update version numbers in all those places all the time. (but I am prepared to accept that as the only viable solution if needed).

What I'd like to do, and this is completely pie-in-the-sky, is have maven do something as part of the building of our packages, where it generates a hash value based on all the *.java files in a package and outputs that value to a resource file which also gets picked up when packaged. The classes within these *.java files, when outputting log messages, will be able to append this hash value somewhere in the log string since the logging framework will read this hash value from this resources file. So at runtime, we can tell which "version" of our packages is actually running. This has its downsides for sure...

but part of me just wants to see if this will work. I'm fairly new to maven and I've been unsuccessful at searching for just the right thing in this case.

let the flames begin...

TS Haines
  • 61
  • 5
  • 4
    Not exactly a flame, but you will be much more efficient if you work with the build group to address their incompetence rather than using hacks to work around them. Why would you want to work in an organization where incompetence goes unaddressed ? – gareth_bowles Jun 03 '14 at 21:35
  • Would it work to just write the maven build number to the resource file? http://stackoverflow.com/questions/3532135/using-maven-to-output-the-version-number-to-a-text-file – yshavit Jun 03 '14 at 21:37
  • You might check the [checksum-maven-plugin](http://nicoulaj.github.io/checksum-maven-plugin/). – khmarbaise Jun 03 '14 at 22:21
  • @gareth_bowles - I ask myself that same question multiple times per day. the organization in question here involves the government... our firm, and this entire group of engineers, regrets this engagement more than words can express. no, it does not involve healthcare.gov. – TS Haines Jun 03 '14 at 22:29
  • @yshavit - maven filtering may be the way to go, at least for now. Coupled with the mojo build helper plugin in order to dynamically set a maven property. It doesn't give me exactly what i'm looking for, but it is not bad in this situation. – TS Haines Jun 03 '14 at 23:30

1 Answers1

0

What you are looking for is a way to operate with build numbers instead of artifact versions. This is a very common-sense approach, which usually works better, so there is nothing wrong with it.

In order for it to work, you need to annotate the artifacts with build name and number metadata. Luckily, when using Artifactory and Jenkins there is a very easy way to do it without the hassle of adding build numbers to files inside the archives or storing additional information in Jenkins or playing with filtered resources in Maven. All you need to do is use the Jenkins Artifactory plugin (if you have an access to Jenkins configuration) or Maven Artifactory plugin (this is totally under your control, since you can change to pom files).

Once configured, the artifacts will be annotated with build names and numbers and you'll be able to get all the information about the build just by knowing the artifact checksum: Checksum search -> Tree Browser -> Builds tab -> Build browser.

JBaruch
  • 22,610
  • 5
  • 62
  • 90
  • And I can output the build name/number at runtime as part of a log message? I do like the simplicity of using annotations and i can easily look in artifactory to match up checksums. I just can't seem to find documentation on how to retrieve the build name/number from within the code itself. – TS Haines Jun 05 '14 at 17:51
  • The buildInfo Json includes the checksums of all the deployed files. You can get this file by [REST API](http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-BuildInfo). – JBaruch Jun 07 '14 at 11:35
  • unfortunately the deployed code, at runtime, will not have network access to the artifactory server. – TS Haines Jun 09 '14 at 20:33
  • Maybe I misunderstood you. You need the build name and number in the log during the build? – JBaruch Jun 09 '14 at 21:22