向自定义gradle插件添加依赖项 [英] Adding dependencies to a custom gradle plugin

查看:314
本文介绍了向自定义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

这篇关于向自定义gradle插件添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆