Skip to content

Commit 9d6465f

Browse files
Use a base template file, and in build time dynamically generate the correct Versions.java file
1 parent b7cf5f6 commit 9d6465f

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

build.gradle

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ ext {
7272
buildRevision = versioning.info.commit
7373
}
7474

75-
task createVersionFile {
76-
new File("${projectDir}/grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/Versions.java").text = """
77-
package net.devh.boot.grpc.common.util;
78-
public final class Versions {
79-
public static final String PROJECT_VERSION = "v${projectVersion}";
80-
private Versions() {}
81-
}
82-
"""
83-
}
84-
8575
clean.doFirst {
8676
delete "${projectDir}/grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/Versions.java"
8777
}
@@ -150,7 +140,18 @@ allprojects {
150140
}
151141
}
152142

153-
// Generate MANIFEST.MF
143+
task createVersionsFile(type: Copy) {
144+
from("src/main/java/net/devh/boot/grpc/common/util/Versions.java.template") {
145+
rename "Versions.java.template", "Versions.java"
146+
}
147+
into "src/main/java/net/devh/boot/grpc/common/util"
148+
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
149+
'VERSIONS_STRING_PLACEHOLDER': "v${projectVersion}".toString(),
150+
])
151+
}
152+
compileJava.dependsOn createVersionsFile
153+
154+
// Generate.MF
154155
jar {
155156
manifest {
156157
attributes(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2016-2023 The gRPC-Spring Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.devh.boot.grpc.common.util;
18+
19+
/**
20+
* Class that contains version strings
21+
*/
22+
public final class Versions {
23+
24+
/**
25+
* A constant that defines, the current version of the library.
26+
*/
27+
public static final String PROJECT_VERSION = "VERSIONS_STRING_PLACEHOLDER";
28+
29+
private Versions() {}
30+
31+
}

0 commit comments

Comments
 (0)