首页 文章

Gradle编译依赖项不包含在Jar中

提问于
浏览
2

我有一个jar,build-plugins.jar,带有gradle插件,在build.gradle中使用它构建:

apply plugin 'java'
    dependencies {
    compile gradleApi()
       compile localGroovy()
       compile('eviware:maven-soapui-plugin:4.5.1')
       compile('org.antlr:stringtemplate:4.0.2')
       compile('commons-io:commons-io:2.4')
       compile('joda-time:joda-time:2.1')
    }

这构建了build-plugins.jar . 并且使用插件的项目按文件引用插件jar

apply plugin 'thepluginwahoo'
buildscript {
dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.1'
        classpath files('/path/to/build-plugins.jar')
    }
}

问题是,当我运行第二个项目的任何任务时,我得到“无法为类xyz创建类代理”,其根本原因是四个依赖项(joda-time,commons-io,stringtemplate,maven-soapui-插件)不在那里 . 如果我将依赖项添加到消耗插件的项目中,那么它可以正常工作:

apply plugin 'thepluginwahoo'
buildscript {
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.1'
        classpath files('/path/to/build-plugins.jar')
        classpath 'eviware:maven-soapui-plugin:4.5.1'
        classpath 'org.antlr:stringtemplate:4.0.2'
        classpath 'joda-time:joda-time:2.1'
        classpath 'commons-io:commons-io:2.4'
    }

}

我的问题是,当插件消耗项目的buildscript的类路径中包含jar时,为什么插件项目中的“编译”依赖项的类不出现在插件消耗项目中 .

1 回答

  • 3

    Jars通常不包含其依赖项 . 相反,它们与某种描述工件依赖关系的元数据描述符(pom.xml或ivy.xml)一起发布到存储库 . 当您直接将jar文件称为依赖项时,Gradle无法知道它的传递依赖性是什么 . 您有几种方法可以解决这个问题:

相关问题