Skip to content

Commit

Permalink
Allow configurations for dependencies in setups
Browse files Browse the repository at this point in the history
Also made it so that bStats and ItemNBT-API were excluded from AnnoyinG API when implementing
  • Loading branch information
srnyx committed Jun 22, 2023
1 parent 0b8566e commit 43d324f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AnnoyingAPIReturn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xyz.srnyx.gradlegalaxy.data

import org.gradle.api.artifacts.ExternalModuleDependency

import xyz.srnyx.gradlegalaxy.utility.setupAnnoyingAPI


class AnnoyingAPIReturn(private val dependencyModule: ExternalModuleDependency? = null, private val annoyingAPIModule: ExternalModuleDependency) {
/**
* The configuration for the dependency that was added via [setupAnnoyingAPI]
*/
fun dependency(configuration: ExternalModuleDependency.() -> Unit) = dependencyModule?.let(configuration)

/**
* The configuration for Annoying API's implementation that was added via [setupAnnoyingAPI]
*/
fun annoyingAPI(configuration: ExternalModuleDependency.() -> Unit) = annoyingAPIModule.configuration()
}
44 changes: 36 additions & 8 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import org.gradle.kotlin.dsl.add
import xyz.srnyx.gradlegalaxy.annotations.Ignore
import xyz.srnyx.gradlegalaxy.enums.PaperVersion
import xyz.srnyx.gradlegalaxy.enums.Repository
import xyz.srnyx.gradlegalaxy.enums.mavenQuick
import xyz.srnyx.gradlegalaxy.enums.repository


/**
* 1. Sets the Java version for the project depending on the version
* 2. Adds the [Repository.SONATYPE_SNAPSHOTS_OLD] repository if the version is 1.15 or below
* 3. Adds the [Repository.MAVEN_CENTRAL] and [Repository.SPIGOT] repositories
* 4. Adds the dependency (org.spigotmc:spigot-api:[getVersionString])
* 4. Returns the dependency annotation (org.spigotmc:spigot-api:[getVersionString])
*
* @param versionString The version of Spigot-API to use
*
* @return The dependency annotation for the provided Spigot-API version
*/
@Ignore
fun Project.spigotAPI(versionString: String): String {
Expand All @@ -28,44 +32,68 @@ fun Project.spigotAPI(versionString: String): String {
getJavaVersionForMC(versionString)?.let(::setJavaVersion)
// Repositories
val version = SemanticVersion(versionString)
if (version.major <= 1 && version.minor <= 15) repositories.mavenQuick(Repository.SONATYPE_SNAPSHOTS_OLD)
repositories.mavenQuick(Repository.MAVEN_CENTRAL, Repository.SPIGOT)
if (version.major <= 1 && version.minor <= 15) repository(Repository.SONATYPE_SNAPSHOTS_OLD)
repository(Repository.MAVEN_CENTRAL, Repository.SPIGOT)
// Dependency
return "org.spigotmc:spigot-api:${getVersionString(versionString)}"
}

/**
* 1. Adds the [Repository.MAVEN_CENTRAL], maven local, and [Repository.SPIGOT] repositories
* 2. Adds the dependency (org.spigotmc:spigot:[getVersionString])
* 2. Returns the dependency annotation (org.spigotmc:spigot:[getVersionString])
*
* @param versionString The version of Spigot to use
*
* @return The dependency annotation for the provided Spigot version
*/
@Ignore
fun Project.spigotNMS(versionString: String): String {
check(hasJavaPlugin()) { "Java plugin is not applied!" }
// Java version
getJavaVersionForMC(versionString)?.let(::setJavaVersion)
// Repositories
repositories.mavenQuick(Repository.MAVEN_CENTRAL, Repository.SPIGOT)
repository(Repository.MAVEN_CENTRAL, Repository.SPIGOT)
repositories.mavenLocal()
// Dependency
return "org.spigotmc:spigot:${getVersionString(versionString)}"
}

/**
* 1. Adds the [Repository.MAVEN_CENTRAL], [Repository.SONATYPE_SNAPSHOTS_OLD], and [Repository.PAPER] repositories
* 2. Adds the dependency ([PaperVersion.groupId]:[PaperVersion.artifactId]:[version]-R0.1-SNAPSHOT)
* 2. Returns the dependency annotation ([PaperVersion.groupId]:[PaperVersion.artifactId]:[version]-R0.1-SNAPSHOT)
*
* @param version The version of Paper to use
*
* @return The dependency annotation for the provided Paper version
*/
@Ignore
fun Project.paper(version: String): String {
check(hasJavaPlugin()) { "Java plugin is not applied!" }
// Java version
getJavaVersionForMC(version)?.let(::setJavaVersion)
// Repositories
repositories.mavenQuick(Repository.MAVEN_CENTRAL, Repository.SONATYPE_SNAPSHOTS_OLD, Repository.PAPER)
repository(Repository.MAVEN_CENTRAL, Repository.SONATYPE_SNAPSHOTS_OLD, Repository.PAPER)
// Dependency
val paperVersion: PaperVersion = PaperVersion.parse(version)
return "${paperVersion.groupId}:${paperVersion.artifactId}:${getVersionString(version)}"
}

/**
* 1. Adds the [Repository.JITPACK] repository
* 2. Returns the dependency to the provided Annoying API version
*
* @param version The version of Annoying API to use
*
* @return The dependency annotation for the provided Annoying API version
*/
fun Project.annoyingAPI(version: String): String {
check(hasJavaPlugin()) { "Java plugin is not applied!" }
// Repositories
repository(Repository.JITPACK)
// Dependency
return "xyz.srnyx:annoying-api:$version"
}

/**
* 1. Adds the provided dependency as an `implementation` dependency
* 2. Relocates the dependency to the provided package
Expand Down
27 changes: 18 additions & 9 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package xyz.srnyx.gradlegalaxy.utility

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.component.SoftwareComponent
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
Expand All @@ -14,13 +15,14 @@ import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo

import xyz.srnyx.gradlegalaxy.annotations.Ignore
import xyz.srnyx.gradlegalaxy.data.AnnoyingAPIReturn
import xyz.srnyx.gradlegalaxy.data.pom.DeveloperData
import xyz.srnyx.gradlegalaxy.data.pom.LicenseData
import xyz.srnyx.gradlegalaxy.data.pom.ScmData
import xyz.srnyx.gradlegalaxy.enums.Repository
import xyz.srnyx.gradlegalaxy.enums.mavenQuick


/**
Expand Down Expand Up @@ -219,10 +221,12 @@ fun Project.setupMC(
replacements: Map<String, String>? = getSentinelReplacements(),
textEncoding: String? = "UTF-8",
archiveClassifier: String? = "",
) {
configuration: Action<ExternalModuleDependency> = Action {}
): ExternalModuleDependency? {
setupJava(group, version, description, javaVersion, textEncoding, archiveClassifier)
dependency?.let { dependencies.add("compileOnly", it) }
replacements?.let(::addReplacementsTask)
if (dependency != null) return addDependencyTo(project.dependencies, "compileOnly", dependency, configuration)
return null
}

/**
Expand Down Expand Up @@ -254,12 +258,17 @@ fun Project.setupAnnoyingAPI(
replacements: Map<String, String>? = getSentinelReplacements(),
textEncoding: String? = "UTF-8",
artifactClassifier: String? = "",
) {
configuration: AnnoyingAPIReturn.() -> Unit = {},
): AnnoyingAPIReturn {
check(hasShadowPlugin()) { "Shadow plugin is required for Annoying API!" }
setupMC(group, version, description, dependency, javaVersion, replacements, textEncoding, artifactClassifier)
repositories { mavenQuick(Repository.JITPACK) }
dependencies { add("implementation", "xyz.srnyx:annoying-api:$annoyingAPIVersion") }
relocate("xyz.srnyx.annoyingapi")
val annoyingAPIReturn = AnnoyingAPIReturn(
setupMC(group, version, description, dependency, javaVersion, replacements, textEncoding, artifactClassifier),
dependencies.implementationRelocate(project, annoyingAPI(annoyingAPIVersion), "xyz.srnyx.annoyingapi") {
exclude("org.bstats", "bstats-bukkit")
exclude("de.tr7zw", "item-nbt-api")
})
annoyingAPIReturn.configuration()
return annoyingAPIReturn
}

/**
Expand Down

0 comments on commit 43d324f

Please sign in to comment.