-
-
Notifications
You must be signed in to change notification settings - Fork 0
Scripts
srnyx edited this page Jun 25, 2024
·
15 revisions
Oh boy, there are TONS of scripts to make setting up your projects 10x easier! Most of them are geared towards Minecraft, but more will be added in the future.
-
makePackageSafe(path: String)
: Simple function that makes the given package path a valid one (e.g. safe to use for relocations or other stuff) -
Project.relocate(from: String, to: String = ...)
: This relocates the specified package to the new package when using the Shadow plugin.to
defaults to the project's group + the project's name (lowercase and without any invalid characters) + libs +from
's last package
-
Project.hasJavaPlugin()
: This will simply return whether or not the Java plugin (java
) is applied, mainly used internally -
Project.hasShadowPlugin()
: This does the same ashasJavaPlugin()
except with the Shadow plugin (com.github.johnrengelman.shadow
) -
Project.getJavaExtension()
: Also used internally, this returns thejava
extension for the Java plugin -
Project.getPackage()
: Returns the main package of the project ($group.${makePackageSafe(name)}
). Primarily used for Minecraft plugins. -
Project.getDefaultReplacements()
: This will return a map of default replacements used foraddReplacementsTask(...)
-
setTextEncoding(encoding: String = "UTF-8")
: UTF-8 is almost always used, so this just makes it a lot easier to set -
setJavaVersion(version: JavaVersion = JavaVersion.VERSION_1_8)
: Since it's either Java 8 or environment, and environment is default, this defaults to Java 8 and only needs to be set if a project requires a version that isn't the environment's -
setShadowArchiveClassifier(classifier: String = "")
: This sets the archive/artifact classifier for the Shadow plugin, which is by default-all
-
Project.addBuildShadowTask()
: This makes thebuild
tasks depend on theshadowJar
task, so that when you rungradle build
, it uses Shadow -
Project.addJavadocSourcesJars(javadocClassifier: String? = null, sourcesClassifier: String? = null)
: Includes the Javadoc and sources JAR file when building, allowing their classifiers to be configured (-javadoc
and-sources
by default) -
Project.addReplacementsTask(replacementFiles: Set<String> = setOf("plugin.yml"), replacements: Map<String, () -> String> = getDefaultReplacements()
: This is super useful for Spigot plugins for theirplugin.yml
. This will replace all instances of${property}
with the provided property in all of the desired files (default justplugin.yml
). -
Project.addCompilerArgs(vararg args: String)
: Adds the specified arguments to java compilation, useful for some JDA (Java Discord API) libraries
This sets up basically your entire project. If Shadow is installed, it'll run addBuildShadowTask()
-
group: String = project.group.toString()
: The group ID of your project (example:xyz.srnyx
) -
version: String = project.version.toString()
: The current version of your project (example:1.0.0
) -
description: String? = project.description
: A short description of the project -
javaVersion: JavaVersion? = null
: The Java version the project should use, leave default/null
to not set (use environment version) -
textEncoding: String? = "UTF-8"
: The text encoding to use when compiling, defaults to UTF-8 -
archiveClassifier: String? = ""
: Sets the archive classifier if the Shadow plugin is applied
// None of the parameters are required, but it may not end up how you want...
setupJava()
// It's highly recommended to have something like this:
setupJava("xyz.srnyx", "3.0.1")
This sets up basically your entire project for Minecraft (although it'll still work for anything else). If Shadow is installed, it'll run addBuildShadowTask()
-
replacementFiles: Set<String>? = setOf("plugin.yml")
: The files that will have replacements processed in them -
replacements: Map<String, String>? = getSentinelReplacements()
: The replacement properties that will be expanded onto YML resource files - The rest of the parameters come from
Project.setupJava(...)
// None of the parameters are required, but it may not end up how you want...
setupMC()
// It's highly recommended to have something like this:
setupMC("xyz.srnyx", "3.0.1")
-
annoyingAPIVersion: String
: The version to use for Annoying API -
configuration: String = "implementation"
: The type of dependency configuration Annoying API should use -
configurationAction: Action<ExternalModuleDependency> = Action {}
: The extra configuration that should be applied to Annoying API's dependency - The rest of the parameters come from
Project.setupMC(...)
// This does have a required parameter, annoyingAPIVersion, but it's the only one
setupAnnoyingAPI("3.0.1")
// But, once again, it's highly recommended to include more:
setupAnnoyingAPI("3.0.1", "xyz.srnyx", "2.0.0")
A simple task that will set up a semi-advanced configuration of publishing for Maven. It'll apply the maven-publish
plugin, create a new MavenPublication
using the specified parameters, and configure it further with the provided configuration
-
groupId: String? = null
: The groups ID to use when publishing -
artifactId: String? = null
: The ID the artifact should use -
version: String? = null
: The version being published -
withJavadocsSourcesJars: Boolean = true
: WhetheraddJavadocSourcesJars()
should be called or not -
component: SoftwareComponent? = components["java"]
: TheSoftwareComponent
to load from -
artifacts: Collection<Any> = emptyList()
: The artifacts that should be published -
name: String? = project.name
: The name of the project -
description: String? = project.description
: The description of the project -
url: String? = null
: The URL that leads to the homepage/documentation of the project -
licenses: List<LicenseData> = emptyList()
: The licenses of the project -
developers: List<DeveloperData> = emptyList()
: Developers & contributors that worked on the project -
scm: ScmData?= null
: Source Control Management (SCM) information to be included -
configuration: MavenPublication.() -> Unit = {}
: Any other configuration information to be applied (after everything else is set)
// None of the parameters are required, as they can all be grabbed from the project itself
setupPublishing()
// Just a few extra parameters to add more details (don't use `DeveloperData.srnyx`)
setupPublishing(
artifactId = "annoying-api",
url = "https://annoying-api.srnyx.com",
licenses = listOf(LicenseData.MIT),
developers = listOf(DeveloperData.srnyx))
© 2023 srnyx
Thank you for using my plugin :)