简体   繁体   English

Gradle + Bintray:正确指定依赖项的依赖项

[英]Gradle + bintray: Specifying Dependencies of dependencies correctly

I have the following scenario: 我有以下情况:

I want to use a project of mine (hosted on bintray.com ) in another project of mine. 我想在另一个我的项目中使用我的一个项目(托管在bintray.com上 )。

I set up a maven repository, uploaded artifacts and pom files and then was able to utilize the jar file(s) uploaded to the bintray maven repo just fine, with the following build.gradle file: 我建立了一个maven存储库,上传了工件和pom文件,然后能够使用以下build.gradle文件很好地利用上传到Bintray Maven存储库的jar文件:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'randers.test.usageTest.UsageTest'

repositories {
    maven { url 'http://dl.bintray.com/randers00/NotEnoughVocab' }
    jcenter()
}

dependencies {
    compile(group: 'randers.notenoughvocab.core', name: 'notenoughvocab-core', version: '0.0.1', ext: 'jar')
}

jar {
    manifest {
        attributes "Main-Class": mainClassName
    }
}

This build file successfully equips the project with my core library and even makes sources, etc. available in the IDE (IntelliJ IDEA I use) 此构建文件成功为项目提供了我的核心库,甚至使源代码等在IDE中可用(我使用的IntelliJ IDEA)

The problem is: The core itself uses libraries, which are not gotten by gradle. 问题是:核心本身使用的库不是通过gradle获取的。

This is the pom file that is on bintray: 这是bintray上的pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>randers.notenoughvocab.core</groupId>
  <artifactId>notenoughvocab-core</artifactId>
  <version>0.0.1</version>
  <dependencies>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.1.3</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.7</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.jdom</groupId>
      <artifactId>jdom2</artifactId>
      <version>2.0.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-configuration</groupId>
      <artifactId>commons-configuration</artifactId>
      <version>1.10</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.2.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <licenses>
    <license>
      <name>GNU General Public License, Version 3.0</name>
      <url>http://www.gnu.org/licenses/gpl.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <contributors>
    <contributor>
      <name>Ruben Anders</name>
      <email>RAnders00@users.noreply.github.com</email>
      <url>https://github.com/RAnders00</url>
    </contributor>
  </contributors>
</project>

I looked at other projects on bintray and their pom files look similar. 我查看了bintray上的其他项目,它们的pom文件看起来很相似。

Declaring the dependecy the traditional and simple way works fine: 用传统和简单的方式声明依赖关系很好:

compile 'randers.notenoughvocab.core:notenoughvocab-core:0.0.1'

It doesn't work when you specify ext: 'jar' , because that is used to download a single artifact. 当您指定ext:'jar'时 ,它不起作用,因为它用于下载单个工件。 From the user guide : 用户指南中

Artifact only notation 仅工件的符号

As said above, if no module descriptor file can be found, Gradle by default downloads a jar with the name of the module. 如上所述,如果找不到模块描述符文件,则默认情况下,Gradle将下载具有模块名称的jar。 But sometimes, even if the repository contains module descriptors, you want to download only the artifact jar, without the dependencies. 但是有时,即使存储库包含模块描述符,您也只希望下载工件jar,而无需依赖项。 [ 14 ] And sometimes you want to download a zip from a repository, that does not have module descriptors. [ 14 ]有时您想从没有模块描述符的存储库中下载一个zip。 Gradle provides an artifact only notation for those use cases - simply prefix the extension that you want to be downloaded with '@' sign: 对于这些用例,Gradle仅提供了一种工件表示法-只需在要下载的扩展名前添加“ @”符号即可:

Example 50.5. 示例50.5 Artifact only notation 仅工件的符号

build.gradle 的build.gradle

 dependencies { runtime "org.groovy:groovy:2.2.0@jar" runtime group: 'org.groovy', name: 'groovy', version: '2.2.0', ext: 'jar' } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM