Skip to content

Commit 65132b0

Browse files
committed
Bake version numbers in at build-time
`getPackage().getImplementationVersion()` may not be reliable, see: 352aac7#commitcomment-25048691 MOE_MIGRATED_REVID=172638406
1 parent 8364f6c commit 65132b0

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

core/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,48 @@
191191
</execution>
192192
</executions>
193193
</plugin>
194+
<plugin>
195+
<groupId>com.google.code.maven-replacer-plugin</groupId>
196+
<artifactId>replacer</artifactId>
197+
<version>1.5.3</version>
198+
<executions>
199+
<execution>
200+
<phase>generate-sources</phase>
201+
<goals>
202+
<goal>replace</goal>
203+
</goals>
204+
</execution>
205+
</executions>
206+
<configuration>
207+
<file>core/src/main/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java.template</file>
208+
<outputFile>${project.build.directory}/generated-sources/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java</outputFile>
209+
<replacements>
210+
<replacement>
211+
<token>%VERSION%</token>
212+
<value>${project.version}</value>
213+
</replacement>
214+
</replacements>
215+
</configuration>
216+
</plugin>
217+
<plugin>
218+
<groupId>org.codehaus.mojo</groupId>
219+
<artifactId>build-helper-maven-plugin</artifactId>
220+
<version>3.0.0</version>
221+
<executions>
222+
<execution>
223+
<id>add-source</id>
224+
<phase>generate-sources</phase>
225+
<goals>
226+
<goal>add-source</goal>
227+
</goals>
228+
<configuration>
229+
<sources>
230+
<source>${project.build.directory}/generated-sources/java/</source>
231+
</sources>
232+
</configuration>
233+
</execution>
234+
</executions>
235+
</plugin>
194236
</plugins>
195237
</build>
196238
</project>

core/src/main/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java renamed to core/src/main/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
class GoogleJavaFormatVersion {
2020

21-
static Object version() {
22-
return Optional.ofNullable(Main.class.getPackage().getImplementationVersion())
23-
.orElse("unknown");
21+
static String version() {
22+
return "%VERSION%";
2423
}
2524
}

0 commit comments

Comments
 (0)