Skip to content

Commit

Permalink
Bake version numbers in at build-time
Browse files Browse the repository at this point in the history
`getPackage().getImplementationVersion()` may not be reliable, see:
352aac7#commitcomment-25048691

MOE_MIGRATED_REVID=172638406
  • Loading branch information
cushon committed Oct 18, 2017
1 parent 8364f6c commit 65132b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
42 changes: 42 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,48 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>core/src/main/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java.template</file>
<outputFile>${project.build.directory}/generated-sources/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java</outputFile>
<replacements>
<replacement>
<token>%VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

class GoogleJavaFormatVersion {

static Object version() {
return Optional.ofNullable(Main.class.getPackage().getImplementationVersion())
.orElse("unknown");
static String version() {
return "%VERSION%";
}
}

1 comment on commit 65132b0

@sormuras
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.