Gradle-一个项目,多个包装,多个罐子 [英] Gradle - one project, multiple packages, multiple jars

查看:67
本文介绍了Gradle-一个项目,多个包装,多个罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问您一个非常基本的问题,但我希望您能抽出时间来帮助我:

I'm asking you about a very basic question but I hope you can find the time to help me:

我正在尝试实现一个Java项目,该项目可以吐出几个不同的程序,这些程序部分地依赖于我的其他项目.

I'm trying to realise a java-project, that can spit out several different programs which partially have dependencies on other projects of mine.

为了简单起见,我想将所有代码放在一个由Gradle运行的项目中,因此,如果我对中央库(例如数据库连接器)进行更改,则所有子程序都会自动接收更改

In order to keep it simple, I want to have all the code in one project, run by Gradle, so if I make changes to a central library (the database connector for example) all the child-programs automatically recieve the changes.

一个例子可能像这样:

项目:

  • program_A
  • central_library
  • program_B

输出:

  • program_A.jar(包括中央库)
  • program_B.jar(包括中央库)

现在,在为此找到正确的构建脚本时,我遇到了很大的麻烦,并且想知道这里是否有人可以帮助我.

Now I'm having serious troubles finding a correct buildscript for this and was wondering if someone here could help me out.

P.S.:由于我是新手,所以如果我应该通过Gradleproject中的不同模块而不是Gradleprojects源文件中的不同包来实现这一点,请随时告诉我:)

P.S. : Since I'm new to this, if I should realize this through different modules within the Gradleproject instead of different packages in the Gradleprojects sourcefile, feel free to tell me :)

推荐答案

一种解决方法是拥有一个根项目,其中包含其他三个项目.

One way to approach this is to have a root project, that holds the three other projects inside of it.

在其 settings.gradle 文件中指定子项目:

Specify the sub-projects inside its settings.gradle file:

rootProject.name = 'RootProject'
include 'program_A'
include 'central_library'
include 'program_B'

有了这个, program_a 可以通过在 build.gradle 中添加依赖项来依赖 central_library :

With this in place, program_a can depend on central_library by adding a dependency in its build.gradle:

dependencies {
    compile project(':central_library')
}

我在我的项目之一中进行了类似的设置,尽管中央库"是根项目,而子模块是测试环境.

I have a similar setup in one of my projects, although the "central library" is the root project and the submodules are test environments.

这篇关于Gradle-一个项目,多个包装,多个罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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