userdev: Deprecate top level dependency functions in favor of DependencyHandler extension (#179)

This commit is contained in:
Jason 2023-02-02 16:25:29 -07:00 committed by GitHub
parent 668e7a0c7c
commit 8a9f7c7462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 171 additions and 1 deletions

View file

@ -1,5 +1,5 @@
group = io.papermc.paperweight
version = 1.4.2-SNAPSHOT
version = 1.5.0-SNAPSHOT
org.gradle.caching = true
org.gradle.parallel = true

View file

@ -91,6 +91,12 @@ abstract class PaperweightUser : Plugin<Project> {
target.objects
)
target.dependencies.extensions.create(
PAPERWEIGHT_EXTENSION,
PaperweightUserDependenciesExtension::class,
target.dependencies
)
createConfigurations(target, target.provider { userdevSetup })
val reobfJar by target.tasks.registering<RemapJar> {

View file

@ -0,0 +1,152 @@
/*
* paperweight is a Gradle plugin for the PaperMC project.
*
* Copyright (c) 2021 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package io.papermc.paperweight.userdev
import io.papermc.paperweight.util.constants.*
import org.gradle.api.Action
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.*
abstract class PaperweightUserDependenciesExtension(
private val dependencies: DependencyHandler
) {
/**
* Adds a dependency on Paper's dev bundle to the dev bundle [org.gradle.api.artifacts.Configuration].
*
* @param version dependency version
* @param group dependency group
* @param artifactId dependency artifactId
* @param configuration dependency configuration
* @param classifier dependency classifier
* @param ext dependency extension
* @param devBundleConfigurationName name of the dev bundle [org.gradle.api.artifacts.Configuration]
* @param configurationAction action configuring the dependency
*/
@JvmOverloads
fun paperDevBundle(
version: String? = null,
group: String = "io.papermc.paper",
artifactId: String = "dev-bundle",
configuration: String? = null,
classifier: String? = null,
ext: String? = null,
devBundleConfigurationName: String = DEV_BUNDLE_CONFIG,
configurationAction: Action<ExternalModuleDependency> = nullAction()
): ExternalModuleDependency {
val dep = dependencies.create(group, artifactId, version, configuration, classifier, ext)
configurationAction(dep)
dependencies.add(devBundleConfigurationName, dep)
return dep
}
/**
* Adds a dependency to the dev bundle [org.gradle.api.artifacts.Configuration].
*
* @param group dependency group
* @param version dependency version
* @param artifactId dependency artifactId
* @param configuration dependency configuration
* @param classifier dependency classifier
* @param ext dependency extension
* @param devBundleConfigurationName name of the dev bundle [org.gradle.api.artifacts.Configuration]
* @param configurationAction action configuring the dependency
*/
@JvmOverloads
fun devBundle(
group: String,
version: String? = null,
artifactId: String = "dev-bundle",
configuration: String? = null,
classifier: String? = null,
ext: String? = null,
devBundleConfigurationName: String = DEV_BUNDLE_CONFIG,
configurationAction: Action<ExternalModuleDependency> = nullAction()
): ExternalModuleDependency {
val dep = dependencies.create(group, artifactId, version, configuration, classifier, ext)
configurationAction(dep)
dependencies.add(devBundleConfigurationName, dep)
return dep
}
/**
* Creates a Paper dev bundle dependency without adding it to any configurations.
*
* @param version dependency version
* @param group dependency group
* @param artifactId dependency artifactId
* @param configuration dependency configuration
* @param classifier dependency classifier
* @param ext dependency extension
* @param configurationAction action configuring the dependency
*/
@JvmOverloads
fun paperDevBundleDependency(
version: String? = null,
group: String = "io.papermc.paper",
artifactId: String = "dev-bundle",
configuration: String? = null,
classifier: String? = null,
ext: String? = null,
configurationAction: Action<ExternalModuleDependency> = nullAction()
): ExternalModuleDependency {
val dep = dependencies.create(group, artifactId, version, configuration, classifier, ext)
configurationAction(dep)
return dep
}
/**
* Creates a dev bundle dependency without adding it to any configurations.
*
* @param group dependency group
* @param version dependency version
* @param artifactId dependency artifactId
* @param configuration dependency configuration
* @param classifier dependency classifier
* @param ext dependency extension
* @param configurationAction action configuring the dependency
*/
@JvmOverloads
fun devBundleDependency(
group: String,
version: String? = null,
artifactId: String = "dev-bundle",
configuration: String? = null,
classifier: String? = null,
ext: String? = null,
configurationAction: Action<ExternalModuleDependency> = nullAction()
): ExternalModuleDependency {
val dep = dependencies.create(group, artifactId, version, configuration, classifier, ext)
configurationAction(dep)
return dep
}
@Suppress("unchecked_cast")
private fun <T> nullAction(): Action<T> {
return NullAction as Action<T>
}
private object NullAction : Action<Any> {
override fun execute(t: Any) {}
}
}

View file

@ -36,6 +36,12 @@ import org.gradle.kotlin.dsl.*
* @param devBundleConfigurationName name of the dev bundle [org.gradle.api.artifacts.Configuration]
* @param configurationAction action configuring the dependency
*/
@Deprecated(
message = "Replaced by extension methods",
replaceWith = ReplaceWith(
"paperweight.paperDevBundle"
)
)
fun DependencyHandlerScope.paperDevBundle(
version: String? = null,
group: String = "io.papermc.paper",
@ -59,6 +65,12 @@ fun DependencyHandlerScope.paperDevBundle(
* @param devBundleConfigurationName name of the dev bundle [org.gradle.api.artifacts.Configuration]
* @param configurationAction action configuring the dependency
*/
@Deprecated(
message = "Replaced by extension methods",
replaceWith = ReplaceWith(
"paperweight.devBundle"
)
)
fun DependencyHandlerScope.paperweightDevBundle(
group: String,
version: String? = null,