Gradle,如何通过设置插件共享目录
Gradle, how to share a catalog via a settings plugin
试用 Gradle 7 中的新目录功能,我正在尝试通过设置插件共享目录
不幸的是 documentation 太短了:
One option to share a catalog is to write a settings plugin, publish it on the Gradle plugin portal or an internal repository, and let the consumers apply the plugin on their settings file.
我通过 gradle init
为使用 kotlin 作为语言和构建脚本的插件开发人员进行了初始化。
然后我将 Project
换成 Settings
并在 producer
上添加了一个虚拟别名
class UpgradedOctoGuacamolePlugin : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.dependencyResolutionManagement {
it.versionCatalogs {
it.create("libs") {
it.alias("groovy-core").to("org.codehaus.groovy:groovy:3.0.5")
}
}
}
}
}
消费者方面settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
}
versionCatalogs {
create("libs") {
from("com.github.elect86:upgraded-octo-guacamole:9f454a68")
}
}
}
但在同步
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all artifacts for configuration 'incomingPlatformsForLibs'.
> Could not resolve com.github.elect86:upgraded-octo-guacamole:9f454a68.
Required by:
unspecified:unspecified:unspecified
> No matching variant of com.github.elect86:upgraded-octo-guacamole:9f454a68 was found. The consumer was configured to find attribute 'org.gradle.internal.dm.model.builder.id' with value '0', attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog' but:
- Variant 'apiElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
- Variant 'runtimeElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 46ms
类别和用法不匹配,需要“平台”和“版本目录”,但只找到“库”和“java-api”
这些是我的制作人变体
19:15:03: Executing task 'outgoingVariants'...
Type-safe dependency accessors is an incubating feature.
> Task :outgoingVariants
--------------------------------------------------
Variant apiElements
--------------------------------------------------
Description = API elements for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Description = Elements of runtime for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- Variant : resources
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = resources
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/resources/main (artifactType = java-resources-directory)
(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.
BUILD SUCCESSFUL in 45ms
1 actionable task: 1 executed
19:15:04: Task execution finished 'outgoingVariants'.
我做错了什么?
我认为我不必自己修改那些属性..
规格:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-milestone-1-all.zip
原来我只需要在 settings.gradle.kts
中直接应用插件,我不知道你能做到这一点
apply {
id("guacamole")
}
试用 Gradle 7 中的新目录功能,我正在尝试通过设置插件共享目录
不幸的是 documentation 太短了:
One option to share a catalog is to write a settings plugin, publish it on the Gradle plugin portal or an internal repository, and let the consumers apply the plugin on their settings file.
我通过 gradle init
为使用 kotlin 作为语言和构建脚本的插件开发人员进行了初始化。
然后我将 Project
换成 Settings
并在 producer
class UpgradedOctoGuacamolePlugin : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.dependencyResolutionManagement {
it.versionCatalogs {
it.create("libs") {
it.alias("groovy-core").to("org.codehaus.groovy:groovy:3.0.5")
}
}
}
}
}
消费者方面settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
}
versionCatalogs {
create("libs") {
from("com.github.elect86:upgraded-octo-guacamole:9f454a68")
}
}
}
但在同步
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all artifacts for configuration 'incomingPlatformsForLibs'.
> Could not resolve com.github.elect86:upgraded-octo-guacamole:9f454a68.
Required by:
unspecified:unspecified:unspecified
> No matching variant of com.github.elect86:upgraded-octo-guacamole:9f454a68 was found. The consumer was configured to find attribute 'org.gradle.internal.dm.model.builder.id' with value '0', attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog' but:
- Variant 'apiElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
- Variant 'runtimeElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 46ms
类别和用法不匹配,需要“平台”和“版本目录”,但只找到“库”和“java-api”
这些是我的制作人变体
19:15:03: Executing task 'outgoingVariants'...
Type-safe dependency accessors is an incubating feature.
> Task :outgoingVariants
--------------------------------------------------
Variant apiElements
--------------------------------------------------
Description = API elements for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Description = Elements of runtime for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- Variant : resources
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = resources
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/resources/main (artifactType = java-resources-directory)
(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.
BUILD SUCCESSFUL in 45ms
1 actionable task: 1 executed
19:15:04: Task execution finished 'outgoingVariants'.
我做错了什么?
我认为我不必自己修改那些属性..
规格:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-milestone-1-all.zip
原来我只需要在 settings.gradle.kts
中直接应用插件,我不知道你能做到这一点
apply {
id("guacamole")
}