问题遇到的现象和发生背景
自定义了一个gradle插件也发行在了本地mavenlocal(),但在想使用这个自定义插件而配置依赖时classpath 报错
遇到的现象和发生背景,请写出第一个错误信息
rootProject叫gradletest
自定义插件的所在module叫myplugin
自定义插件的class叫PluginTest
详细目录
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
- 这是rootProject的build.gralde
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath group :'com.sunrain.plugin' ,name :'library' ,version :'1.1'//这里报错
}
}
plugins {
id 'java'
}
group = 'com.sunrian'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
test {
useJUnitPlatform()
}
- 这是自定义插件所在module的build.gralde
apply plugin: 'groovy' //必须
apply plugin: 'maven-publish'
dependencies {
implementation gradleApi() //必须
implementation localGroovy() //必须
}
repositories {
google()
mavenLocal()
jcenter()
mavenCentral() //必须
}
sourceSets { main {
groovy {
srcDir 'src/main/groovy' }
}
}
publishing {
publications {
myLibrary(MavenPublication) {
groupId = 'com.sunrain.plugin' //指定GAV坐标信息
artifactId = 'library'
version = '1.1'
from components.java//发布jar包
//from components.web///引入war插件,发布war包
}
}
repositories {
mavenLocal()
}
}
- 这是myplugin下的properties文件内容
implementation-class=com.sunrain.PluginTest
- 这是实际发行在mavenLoca()上的自定义插件位置
运行结果及详细报错内容
PS D:\workspace_idea\gradletest> gradle clean
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'gradletest'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.sunrain.plugin:library:1.1.
Required by:
project :
> No matching variant of com.sunrain.plugin:library:1.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute '
org.gradle.plugin.api-version' with value '8.0.2' but:
- Variant 'apiElements' capability com.sunrain.plugin:library:1.1 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0.2')
- Variant 'runtimeElements' capability com.sunrain.plugin:library:1.1 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0.2')
* 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 1s
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
- 首先的看一下mavenLocal有没有自定义插件,但好像有
- 然后是classpath要求的gav坐标对不对,但好像也对
- 不知道了
我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
可以通过依赖找到在mavenLocal中的自定义插件