Gradle中的相对项目依赖关系? [英] Relative project dependencies in Gradle?

查看:85
本文介绍了Gradle中的相对项目依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当指定Gradle项目依赖关系时,我是否可以避免使用完整的绝对项目名称并使用相对项目名称? (即在我的示例中,我不想明确指定:引用时:app-a:domain-a)

  //目录结构
app-a /
domain -a /
build.gradle
webapp-a /
build.gradle

WebApp-A build.gradle:

 应用插件:'java'

//为webapp-a
依赖关系{

//工程
编译项目(':app -a:domain -a')

//不工作
编译项目(projectDir.path +'/../domain-a/')

//不工作
编译findProject('../ domain-a')

//不工作
编译项目(':domain-a ')
}


解决方案

不好的主意,因为他们让你的项目依赖于它所在的更广泛的项目。情况并非如此。我建议避免使用相对名称。

在将父项目作为依赖项检索方面,这可以通过默认的父​​目录来完成,或者如果不使用通常的依赖项解析机制,坐标(groupId,artifactId和版本)并在本地存储库中查找工件。


When specifying Gradle project dependencies, can I avoid using a full absolute project name and use a relative one instead? (i.e. in my example I don't want to explicitly specify :app-a when referencing :domain-a)

//Directory structure
app-a/
  domain-a/
    build.gradle
  webapp-a/
    build.gradle

WebApp-A build.gradle:

apply plugin: 'java'

//Build.gradle for webapp-a
dependencies {

  // Works
  compile project(':app-a:domain-a')

  //Doesn't work
  compile project(projectDir.path + '/../domain-a/')

  //Doesn't work
  compile findProject('../domain-a')

  //Doesn't work
  compile project(':domain-a')
}

解决方案

Relative names are a bad idea since they make your project depend on the wider project it is located in. That should not be the case. I suggest to avoid using the relative name.

In terms of retrieving the parent project as a dependency this would be done via the default being the parent directory or that failing it would use the usual dependency resolution mechanism, which uses the coordinates (groupId, artifactId and version) and looks the artifact up in the local repository..

这篇关于Gradle中的相对项目依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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