Skip to content

Commit f4fb837

Browse files
authored
Use dedicated properties file for buildscript (#115)
* move build properties to separate file * recreate gradle.properties with base props * adjust readme and errors in build.gradle * add missing comment for file, adjust comments * set properties correctly * adjust editing .properties file info
1 parent 47a8feb commit f4fb837

File tree

4 files changed

+235
-202
lines changed

4 files changed

+235
-202
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ This build script was heavily inspired by the build script created by GT New Hor
3030
- Automatic mod version detection from the latest git tag (or manually specified, if you prefer)
3131
- Updated Launchwrapper for better ASM/mixin debugging options
3232

33-
And many more to come! And of course, all of these features are toggleable via an option in `gradle.properties`.
33+
And many more to come! And of course, all of these features are toggleable via an option in `buildscript.properties`,
34+
a custom file separate from `gradle.properties` for ease of use.
3435

3536
## How to Install (New Project)
3637
- Download the latest **starter.zip** release from [here](https://github.com/GregTechCEu/Buildscripts/releases) and extract into your project directory
3738
- Import into your IDE (we recommend IntelliJ IDEA, as it has the best support for modded Minecraft)
3839
- Choose a license for your code
3940
- Ensure your project is initialized in git. For example, you can run `git init; git commit --message "initial commit"`
40-
- Replace placeholder values, such as `gradle.properties`, package/class names for your `src/main` directory, etc.
41+
- Replace placeholder values, such as in `buildscript.properties`, package/class names for your `src/main` directory, etc.
4142
- Run `./gradlew setupDecompWorkspace`
4243
- Run `./gradlew updateBuildScript` to ensure that you are on the latest version
4344
- You are good to go! You can now run the `runClient` run configuration or run `./gradlew runClient` to launch the game
@@ -47,30 +48,32 @@ And many more to come! And of course, all of these features are toggleable via a
4748
- Rename your `build.gradle` file to `build.gradle.old`
4849
- Copy the [`build.gradle`](https://github.com/GregTechCEu/Buildscripts/blob/master/build.gradle), [`dependencies.gradle`](https://github.com/GregTechCEu/Buildscripts/blob/master/dependencies.gradle), and [`repositories.gradle`](https://github.com/GregTechCEu/Buildscripts/blob/master/repositories.gradle) files from this zip to your project
4950
- Copy the [`settings.gradle`](https://github.com/GregTechCEu/Buildscripts/blob/master/settings.gradle) file from this zip to your project and replace your current one
50-
- Copy all the options from the [`gradle.properties`](https://github.com/GregTechCEu/Buildscripts/blob/master/gradle.properties) file to your `gradle.properties` (or copy entirely if you did not have one). You can leave your existing options if you know you need them, otherwise they can likely be removed
51-
- Configure `gradle.properties` for your mod
51+
- Copy the [`buildscript.properties`](https://github.com/GregTechCEu/Buildscripts/blob/master/buildscript.properties) file from this zip to your project
52+
- Configure `buildscript.properties` to adjust the `build.gradle` settings to suit your project
53+
- Configure `gradle.properties` to create any property settings for use in other gradle files - primarily `dependencies.gradle`
5254
- Move the necessary `dependencies` and/or `repositories` from `build.gradle.old` to the respective files (`dependencies.gradle`, `repositories.gradle`)
53-
- NOTE that if you enable the `includeWellKnownRepositories` option in `gradle.properties`, this build script will automatically have the following Maven locations, meaning you don't need to add them yourself in `repositories.gradle`:
55+
- NOTE that if you enable the `includeWellKnownRepositories` option in `buildscript.properties`, this build script will automatically have the following Maven locations, meaning you don't need to add them yourself in `repositories.gradle`:
5456
1. Curse Maven
5557
2. Modrinth Maven
5658
3. BlameJared Maven
5759
4. CleanroomMC Maven
58-
- NOTE that if you enable the `includeCommonDevEnvMods` option in `gradle.properties`, this build script will automatically have the following Mods, meaning you don't need to add them yourself in `dependencies.gradle`:
60+
- NOTE that if you enable the `includeCommonDevEnvMods` option in `buildscript.properties`, this build script will automatically have the following Mods, meaning you don't need to add them yourself in `dependencies.gradle`:
5961
1. JEI
6062
2. The One Probe
6163
- Delete the `build.gradle.old` file
6264
- And lastly, run `./gradlew updateBuildScript` to ensure that you are on the latest version
6365

6466
### Advanced
6567
- If your project was using Mixins, you may get a new mixin config file generated as `mixins.{modid}.json`, if yours was not named this way. Currently, you will have to move your Mixin config options to this newly generated file. If this behavior does not suit your needs, feel free to open an issue and start a discussion on different behavior
66-
- If your project was using environment variables for CI deployments, see the `gradle.properties` file's comments to view the environment variable names this script checks for
68+
- If your project was using environment variables for CI deployments, see the `buildscript.properties` file's comments to view the environment variable names this script checks for
6769
- If you have any additional build script code that you need to be applied, create an `addon.gradle` file and put it there
6870
- If your project has no dependencies, you can safely delete the `repositories.gradle` and `dependencies.gradle` files, they are optional
6971

7072
## How to Use
7173
### Files
7274
- `build.gradle`: This file is automatically updated, and as a result should not be modified by the user directly
73-
- `gradle.properties`: Contains all the user configuration for the build script
75+
- `buildscript.properties`: Contains all the user configuration for the build script
76+
- `gradle.properties`: Contains all the user configuration for general gradle files
7477
- `settings.gradle`: This file contains some basic setup of the build script. It is currently not versioned, so it is safe to add to, though should not have things removed from it
7578
### Custom Files
7679
Any of these files can optionally be either `.gradle` (Groovy), or `.gradle.kts` (Kotlin DSL).

build.gradle

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
5050

5151

5252
// Project properties
53+
loadProjectProperties()
54+
5355

5456
// Required properties: we don't know how to handle these being missing gracefully
5557
checkPropertyExists("modName")
@@ -1475,14 +1477,28 @@ tasks.register('faq') {
14751477
"To add new dependencies to your project, place them in 'dependencies.gradle', NOT in 'build.gradle' as they would be replaced when the script updates.\n" +
14761478
"To add new repositories to your project, place them in 'repositories.gradle'.\n" +
14771479
"If you need additional gradle code to run, you can place it in a file named 'addon.gradle' (or either of the above, up to you for organization).\n\n" +
1478-
"If your build fails to recognize the syntax of newer Java versions, enable Jabel in your 'gradle.properties' under the option name 'enableModernJavaSyntax'.\n" +
1480+
"If your build fails to recognize the syntax of newer Java versions, enable Jabel in your 'buildscript.properties' under the option name 'enableModernJavaSyntax'.\n" +
14791481
"To see information on how to configure your IDE properly for Java 17, see https://github.com/GregTechCEu/Buildscripts/blob/master/docs/jabel.md\n\n" +
14801482
"Report any issues or feature requests you have for this build script to https://github.com/GregTechCEu/Buildscripts/issues\n")
14811483
}
14821484
}
14831485

14841486

14851487
// Helpers
1488+
def loadProjectProperties() {
1489+
def configFile = file("buildscript.properties")
1490+
if (configFile.exists()) {
1491+
configFile.withReader {
1492+
def prop = new Properties()
1493+
prop.load(it)
1494+
new ConfigSlurper().parse(prop).forEach { String k, def v ->
1495+
project.ext.setProperty(k, v)
1496+
}
1497+
}
1498+
} else {
1499+
print("Failed to read from buildscript.properties, as it did not exist!")
1500+
}
1501+
}
14861502

14871503
def getDefaultArtifactGroup() {
14881504
def lastIndex = project.modGroup.lastIndexOf('.')
@@ -1495,7 +1511,7 @@ def getFile(String relativePath) {
14951511

14961512
def checkPropertyExists(String propertyName) {
14971513
if (!project.hasProperty(propertyName)) {
1498-
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GregTechCEu/Buildscripts/blob/main/gradle.properties")
1514+
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"buildscript.properties\" or \"gradle.properties\". You can find all properties and their description here: https://github.com/GregTechCEu/Buildscripts/blob/main/buildscript.properties and https://github.com/GregTechCEu/Buildscripts/blob/main/gradle.properties")
14991515
}
15001516
}
15011517

buildscript.properties

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#
2+
# The "buildscript.properties" file contains settings loaded and used by the "build.gradle" file.
3+
# For settings loaded in all gradle files or custom settings, use "gradle.properties" instead.
4+
# New properties should not be created in this file, use "gradle.properties" instead.
5+
#
6+
7+
# The name of your mod. Can be any sequence of characters.
8+
modName = MyMod
9+
10+
# This is a case-sensitive string to identify your mod.
11+
# Must be less than 64 characters and all lowercase. Convention is to only contain alphabetic characters.
12+
modId = mymodid
13+
14+
# Project package location.
15+
modGroup = com.myname.mymodid
16+
17+
# Version of your mod.
18+
# This field can be left empty if you want your mod's version to be determined by the latest git tag instead.
19+
modVersion = 1.0.0
20+
21+
# Whether to use the old jar naming structure (modid-mcversion-version) instead of the new version (modid-version)
22+
includeMCVersionJar = false
23+
24+
# The name of your jar when you produce builds, not including any versioning info
25+
modArchivesBaseName = mymodid
26+
27+
# Will update your build.gradle automatically whenever an update is available
28+
autoUpdateBuildScript = false
29+
30+
minecraftVersion = 1.12.2
31+
32+
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
33+
# restart Minecraft in development. Choose this dependent on your mod:
34+
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
35+
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
36+
# Alternatively this can be set with the 'DEV_USERNAME' environment variable.
37+
developmentEnvironmentUserName = Developer
38+
39+
# Additional arguments applied to the JVM when launching minecraft
40+
# Syntax: -arg1=value1;-arg2=value2;...
41+
# Example value: -Dmixin.debug.verify=true;-XX:+UnlockExperimentalVMOptions
42+
additionalJavaArguments =
43+
44+
# Enables using modern java syntax (up to version 17) via Jabel, while still targeting JVM 8.
45+
# See https://github.com/bsideup/jabel for details on how this works.
46+
# Using this requires that you use a Java 17 JDK for development.
47+
enableModernJavaSyntax = true
48+
49+
# Enables runClient/runServer tasks for Java 17 and Java 21 using LWJGL3ify.
50+
# This is primarily used to test if your mod is compatible with platforms running
51+
# Minecraft 1.12.2 on modern versions of Java and LWJGL, and assist in fixing any problems with it.
52+
# Using this requires that you use a Java 17/Java 21 JDK for development.
53+
enableJava17RunTasks = false
54+
55+
# Generate a class with String fields for the mod id, name and version named with the fields below
56+
generateGradleTokenClass = com.myname.mymodid.Tags
57+
gradleTokenModId = MODID
58+
gradleTokenModName = MODNAME
59+
gradleTokenVersion = VERSION
60+
61+
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
62+
# leave this property empty.
63+
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
64+
apiPackage =
65+
66+
# If you want to keep your API code in src/api instead of src/main
67+
useSrcApiPath = false
68+
69+
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/
70+
# There can be multiple files in a comma-separated list.
71+
# Example value: mymodid_at.cfg,jei_at.cfg
72+
accessTransformersFile =
73+
74+
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
75+
usesMixins = false
76+
# Mixin Provider to use. Primarily changed when needing to use a different version.
77+
mixinProviderSpec = zone.rong:mixinbooter:10.6
78+
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
79+
mixinsPackage =
80+
# Location of the mixin config refmap. If left, blank, defaults to "mixins.${modId}.refmap.json". Target file must have the "json" extension.
81+
mixinConfigRefmap =
82+
# Automatically generates a mixin config json if enabled, with the name mixins.modid.json
83+
generateMixinConfig = true
84+
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
85+
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
86+
coreModClass =
87+
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod (meaning that
88+
# there is no class annotated with @Mod) you want this to be true. When in doubt: leave it on false!
89+
containsMixinsAndOrCoreModOnly = false
90+
91+
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
92+
forceEnableMixins = false
93+
94+
# Outputs pre-transformed and post-transformed loaded classes to run/CLASSLOADER_TEMP. Can be used in combination with
95+
# diff to see exactly what your ASM or Mixins are changing in the target file.
96+
# Optionally can be specified with the 'CORE_MOD_DEBUG' env var. Will output a lot of files!
97+
enableCoreModDebug = false
98+
99+
# Adds CurseMaven, Modrinth Maven, BlameJared maven, and some more well-known 1.12.2 repositories
100+
includeWellKnownRepositories = true
101+
102+
# Adds JEI and TheOneProbe to your development environment. Adds them as 'implementation', meaning they will
103+
# be available at compiletime and runtime for your mod (in-game and in-code).
104+
# Overrides the above setting to be always true, as these repositories are needed to fetch the mods
105+
includeCommonDevEnvMods = true
106+
107+
# Some mods require a specific forge version to launch in. When you need to use one of those mods as a dependency,
108+
# and cannot launch with the forge version required, enable this to strip the forge version requirements from that mod.
109+
# This will add 'strip-latest-forge-requirements' as 'runtimeOnlyNonPublishable'.
110+
# Requires useMixins or forceEnableMixins to be true, as the mod uses mixins to function.
111+
stripForgeRequirements = false
112+
113+
114+
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
115+
# responsibility check the licence and request permission for distribution, if required.
116+
usesShadowedDependencies = false
117+
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
118+
# their own classes, making the minimization unreliable.
119+
minimizeShadowedDependencies = true
120+
# If disabled, won't rename the shadowed classes.
121+
relocateShadowedDependencies = true
122+
123+
# Separate run directories into "run/client" for runClient task, and "run/server" for runServer task.
124+
# Useful for debugging a server and client simultaneously. If not enabled, it will be in the standard location "run/"
125+
separateRunDirectories = false
126+
127+
# The display name format of versions published to Curse and Modrinth. $MOD_NAME and $VERSION are available variables.
128+
# Default: $MOD_NAME \u2212 $VERSION. \u2212 is the minus character which looks much better than the hyphen minus on Curse.
129+
versionDisplayFormat = $MOD_NAME \u2212 $VERSION
130+
131+
# Publishing to modrinth requires you to set the MODRINTH_API_KEY environment variable to your current modrinth API token.
132+
133+
# The project's ID on Modrinth. Can be either the slug or the ID.
134+
# Leave this empty if you don't want to publish on Modrinth.
135+
# Alternatively this can be set with the 'MODRINTH_PROJECT_ID' environment variable.
136+
modrinthProjectId =
137+
138+
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
139+
# Syntax: scope1-type1:name1;scope2-type2:name2;...
140+
# Where scope can be one of [required, optional, incompatible, embedded],
141+
# type can be one of [project, version],
142+
# and the name is the Modrinth project or version slug/id of the other mod.
143+
# Example: required-project:jei;optional-project:top;incompatible-project:gregtech
144+
modrinthRelations =
145+
146+
147+
# Publishing to CurseForge requires you to set the CURSEFORGE_API_KEY environment variable to one of your CurseForge API tokens.
148+
149+
# The project's numeric ID on CurseForge. You can find this in the About Project box.
150+
# Leave this empty if you don't want to publish on CurseForge.
151+
# Alternatively this can be set with the 'CURSEFORGE_PROJECT_ID' environment variable.
152+
curseForgeProjectId =
153+
154+
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
155+
# Syntax: type1:name1;type2:name2;...
156+
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
157+
# and the name is the CurseForge project slug of the other mod.
158+
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
159+
curseForgeRelations =
160+
161+
# This project's release type on CurseForge and/or Modrinth
162+
# Alternatively this can be set with the 'RELEASE_TYPE' environment variable.
163+
# Allowed types: release, beta, alpha
164+
releaseType = release
165+
166+
# Generate a default changelog for releases. Requires git to be installed, as it uses it to generate a changelog of
167+
# commits since the last tagged release.
168+
generateDefaultChangelog = false
169+
170+
# Prevent the source code from being published
171+
noPublishedSources = false
172+
173+
174+
# Publish to a custom maven location. Follows a few rules:
175+
# Group ID can be set with the 'ARTIFACT_GROUP_ID' environment variable, default to 'project.group'
176+
# Artifact ID can be set with the 'ARTIFACT_ID' environment variable, default to 'project.name'
177+
# Version can be set with the 'RELEASE_VERSION' environment variable, default to 'modVersion'
178+
# For maven credentials:
179+
# Username is set with the 'MAVEN_USER' environment variable, default to "NONE"
180+
# Password is set with the 'MAVEN_PASSWORD' environment variable, default to "NONE"
181+
customMavenPublishUrl =
182+
183+
# The group for maven artifacts. Defaults to the 'project.modGroup' until the last '.' (if any).
184+
# So 'mymod' becomes 'mymod' and 'com.myname.mymodid' 'becomes com.myname'
185+
mavenArtifactGroup =
186+
187+
# Enable spotless checks
188+
# Enforces code formatting on your source code
189+
# By default this will use the files found here: https://github.com/GregTechCEu/Buildscripts/tree/master/spotless
190+
# to format your code. However, you can create your own version of these files and place them in your project's
191+
# root directory to apply your own formatting options instead.
192+
enableSpotless = false
193+
194+
# Enable JUnit testing platform used for testing your code.
195+
# Uses JUnit 5. See guide and documentation here: https://junit.org/junit5/docs/current/user-guide/
196+
enableJUnit = true
197+
198+
# Deployment debug setting
199+
# Uncomment this to test deployments to CurseForge and Modrinth
200+
# Alternatively, you can set the 'DEPLOYMENT_DEBUG' environment variable.
201+
deploymentDebug = false

0 commit comments

Comments
 (0)