-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cli add version argument #376
Conversation
https://github.com/onthegomap/planetiler/actions/runs/3553600311 ℹ️ Base Logs 3a434a4
ℹ️ This Branch Logs 293ab4a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting this started! Sorry for the delay... a couple of comments and tweaks, let me know what you think.
planetiler-core/src/main/java/com/onthegomap/planetiler/Planetiler.java
Outdated
Show resolved
Hide resolved
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful to print the git hash and build time as well as version. It looks like this approach would give us that: https://jdonkervliet.com/2021/10/22/git-version-in-jar.html - you'd just have to add the buildnumber-maven-plugin, and configure maven-jar-plugin to add the Implementation-Build and Implementation-Timestamp properties. I tried it locally and got:
./mvnw -DskipTests clean package && unzip -p planetiler-dist/target/planetiler-dist-0.6-SNAPSHOT.jar META-INF/MANIFEST.MF
...
Implementation-Title: planetiler-dist
Implementation-Version: 0.6-SNAPSHOT
Implementation-Vendor-Id: com.onthegomap.planetiler
Implementation-Build: bd9f3ab22258da4eb9e6a5b0cbefd00fb0ff6df9
Implementation-Timestamp: 2022-11-11T11:11:20Z
Then we'd just have to figure out how to get those properties out of MANIFEST.MF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which POMs did you add the plugin to to get it to add stuff to manifest?
This should allow getting info from manifest https://stackoverflow.com/a/3777116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! That snippet looks like it should do it. I was able to get those in the manifest by adding to the root pom.xml build/plugins section:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
and also:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Implementation-Timestamp>${maven.build.timestamp}</Implementation-Timestamp>
</manifestEntries>
</archive>
</configuration>
</plugin>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I checked and adding those two plugins makes build add version info to JAR but only to the smaller JAR without dependencies. Fat JAR with dependencies doesn't have that info.
Is that expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also how do you run the no-deps file?
I'm running:
$ java -cp planetiler-dist/target/planetiler-dist-0.6-SNAPSHOT.jar com.onthegomap.planetiler.Main --version
and get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openmaptiles/OpenMapTilesMain
Running the jar with dependencies work but since version is not in manifest it just prints null values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this approach looks problematic because the jars get built so many different ways (jib, assembly plugin, regular maven). Here's another approach that appears to work: c10f08d - basically it just builds a resource file in planetiler-core that captures the build info from maven and that goes everywhere the class files go so we don't need to worry about adding it to all the manifests. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also how do you run the no-deps file
you need to add all of the transitive dependencies to the classpath as well. It gets a little tricky to find them all, something like `java -cp "planetiler-dist/target/planetiler-dist-0.6-SNAPSHOT.jar:planetiler-core/target/planetiler-core-0.6-SNAPSHOT.jar:..." com.onthegomap.planetiler.Main --version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think?
Looks better than the previous solution :)
… after version has been printed
Fixes #326 |
Looks great, thanks @ttomasz ! |
Kudos, SonarCloud Quality Gate passed! |
I saw #326 and even though I have no experience with Java I thought it would be easy enough to add.
Let me know if this approach is ok or not.
Running
$ java -jar planetiler-dist/target/planetiler-dist-*-with-deps.jar --version
results in logger printing arguments and versions of modules at the end: