Skip to content

Commit b1c7cdb

Browse files
Merge pull request #43 from EatSleepProgramRepeat/42-gradlew-build-has-44-errors
fixed gradle errors and made version.properties work with gradle
2 parents 9c0ef3f + 80337fe commit b1c7cdb

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

build.gradle.kts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
* This is the main build file.
99
*/
1010

11+
import java.util.Properties
12+
import java.io.FileInputStream
13+
14+
val versionProperties = Properties()
15+
file("src/main/resources/version.properties").takeIf { it.exists() }?.let {
16+
versionProperties.load(FileInputStream(it))
17+
}
18+
1119
plugins {
1220
id("java")
1321
id("application")
1422
}
1523

1624
group = "org.example"
17-
version = "1.0-SNAPSHOT"
25+
version = versionProperties.getProperty("version", "0.0-VERSION-ERROR")
1826

1927
repositories {
2028
mavenCentral()
@@ -34,4 +42,18 @@ tasks.test {
3442
application {
3543
mainClass.set("com.CDPrintable.Main")
3644
applicationDefaultJvmArgs = listOf("-Djava.library.path=build/libs")
45+
}
46+
47+
java {
48+
toolchain {
49+
languageVersion.set(JavaLanguageVersion.of(22))
50+
}
51+
}
52+
53+
tasks.named<Jar>("jar") {
54+
manifest {
55+
attributes(
56+
"Main-Class" to "com.CDPrintable.Main"
57+
)
58+
}
3759
}

src/main/java/com/CDPrintable/Constants.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@
1010

1111
package com.CDPrintable;
1212

13+
import java.io.InputStream;
14+
import java.util.Properties;
15+
1316
public class Constants {
1417
// MAJOR MINOR PATCH
15-
public static final String VERSION = "1.6.4";
18+
public static final String VERSION;
19+
static {
20+
Properties prop = new Properties();
21+
String tempVersion = "0.0.0"; // Default version
22+
try (InputStream input = Constants.class.getClassLoader().getResourceAsStream("version.properties")) {
23+
if (input != null) {
24+
prop.load(input);
25+
tempVersion = prop.getProperty("version");
26+
} else {
27+
System.err.println("version.properties not found in resources.");
28+
}
29+
} catch (Exception e) {
30+
System.err.println("Failed to load version.properties: " + e.getMessage());
31+
}
32+
VERSION = tempVersion;
33+
}
1634

1735
public static final boolean USER_AGENT_EMAIL_CHANGED = false;
1836

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Application version.
2+
3+
# MAJOR MINOR PATCH
4+
version=1.7.5

0 commit comments

Comments
 (0)