gradle 不支持多级子模块,Gradle多模块项目设置

I've recently started using Gradle and replacing my existing Maven-based projects. I have had many issues in the past with handling multi-module builds with Maven. Gradle has been a breath of fresh air when handling multi-module buils, but it's not perfect yet.

I have the following folder layout for my projects:

-- Projects

---- EnterpriseApp1

------ EarProject

-------- build.gradle

------ EjbProject

-------- build.gradle

------ WarProject

-------- build.gradle

------ properties.gradle

------ build.gradle

---- CommonLib

------ build.gradle

---- ClientApplication

------ build.gradle

The problem I am having is that the "EnterpriseApp1" and "ClientApplication" both depend on the CommonLib project. I don't know how to configure my "EnterpriseApp1" build file to use the CommonLib project as dependency for the "EjbProject". I have come very close to getting this to work, but not quite working yet. I have had success by copying the CommonLib folder inside "EnterpriseApp1", but that's not a long term solution.

Here's my current properties.gradle file in "EnterpriseApp1":

include "EarProject", "EjbProject", "WarProject"

includeFlat "CommonLib"

According to the Gradle documentation the "includeFlat" command in the "settings.gradle" file will include projects in the same lever as the folder where the "settings.gradle" file is (desired behavior).

EnterpriseApp1/build.gradle file:

subprojects {

apply plugin: 'java'

sourceCompatibility = 1.6

group = 'org.example'

version = '1.0-SNAPSHOT'

repositories {

mavenCentral()

...

}

dependencies {

}

}

EnterpriseApp1/EjbProject/build.gradle:

apply plugin: 'java'

sourceCompatibility = 1.6

repositories {

mavenCentral()

...

}

dependencies {

compile project(':CommonLib')

compile group: 'org.restlet.jee', name: 'org.restlet', version: '2.0.11'

compile group: 'ma.glasnost.orika', name: 'orika-core', version: '1.0'

...

compile group: 'javax.jmdns', name: 'jmdns', version: '3.4.1'

}

When I execute "gradle clean build" from the EnterpriseApp1 folder all the dependencies are downloaded as expected and the projects begin to compile (including the CommonLib project), but the EjbProject project fails during the build due to the fact it's missing the CommonLib jar reference. Gradle is not smart enough (or I'm completely clueless ;)) to configure my EjbProject to use the Jar generated from the CommonLib project build stage.

I apologize for the long and complicated setup. I have been working on trying to figure this out for some time now, but have nearly ran out of ideas. I would really appreciate any help for the community.

Thanks!

解决方案

The directory layout that you've chosen already hints at a good solution. I suggest to have three separate builds: EnterpriseApp1, CommonLib, and ClientApplication. I'd publish CommonLib to a Maven or Ivy repository so that the other two builds can consume it from there. For local development you can publish CommonLib to the local Maven repo (easiest) or a file-based Ivy repo.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值