向自定义gradle插件添加依赖项
我正在创建使用gson的gradle插件,但是当我在客户端使用该插件时,它将抛出此java.lang.NoClassDefFoundError: com/google/gson/Gson
我希望我以错误的方式在插件中链接了我的依赖项,但是我不确定,因此任何帮助都将非常有用.
I'm creating a gradle plugin that uses gson, but when I use the plugin at my client it throws this java.lang.NoClassDefFoundError: com/google/gson/Gson
I expect I am linking my dependencies in the plugin in a wrong way, but i'm not quite sure so any help would be great.
插件中的build.gradle
The build.gradle in the plugin
group 'nl.daanluttik.gradle'
version '0.1'
apply plugin: 'java'
apply plugin: 'maven' // the plugin to distribute to maven
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '1.7.2'
compile gradleApi()/*The gradle plugin api*/
testCompile group: 'junit', name: 'junit', version: '4.11'
}
//To distribute to maven
uploadArchives {
repositories {
mavenLocal()
}
}
客户端项目中buildgradle的一部分
A segment of the buildgradle in the client project
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath group: 'nl.daanluttik.gradle', name: 'peach', version: '0.1'
}
}
您因依赖项而缺少pom文件.如果只是java,那么您可以轻松地使用maven-publish
,它将为您正确生成pom.
Your missing the pom file with your dependencies. If it's just java then you can easily use the maven-publish
which will generate the pom for you correctly.
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
groupId 'nl.daanluttik.gradle'
artifactId 'peach'
version '0.1'
from components.java
}
}
}
然后您可以使用gradle publish
参考: https://docs.gradle.org/current/userguide/publishing_maven. html