【发布时间】:2018-03-12 20:21:36
【问题描述】:
项目结构:
root
-- 0. CAN'T add multi-project here
----\ a. ProjectCommonUtil
----\ b. ProjectWeb
----\ c. ProjectBatchUtil
----\ d. ProjectHttpClientUtil
----\ e. ProjectBatchWithMainClass
----\ lib
依赖关系:
- ProjectCommonUtil -> 无
- ProjectWeb -> a、c、d
- ProjectBatchUtil -> 无
- ProjectHttpClientUtil -> 一个
- ProjectBatchWithMainClass -> b, c, d(a)
不用担心开源依赖,这就是我正在努力解决的问题:
-
能够单独构建每个项目
-
依赖关系应该在 lib 文件夹 jars 中确定
-
如果缺少依赖jar,构建依赖并cc:jar到lib文件夹
例如:d 取决于 a。 a 的 jar 不在 lib 文件夹中,所以构建一个然后放在 lib 文件夹中,然后构建 d
这些是我在下面提供的包含的
build.gradle文件
-
-
- 上述结构中的lib文件夹包含
- a、b 的罐子(是的,以罐子形式 b/c 的 e)、c、d、e
- b 的 Ear 文件。 ProjectWeb,在 b 中相应的 WEB-INF/lib 文件夹中包含 jars a、c、d。项目网
我无法在根项目和现有项目之间创建 gradle 多项目,也无法创建胖 jar。也许我正在尝试对 gradle 进行微观管理,但这个 #2 是我需要的,因为我需要将 web ear 部署到应用服务器和批处理(e.),并且它依赖于多个位置的多个运行 e 变体的 linux VM。使用不同的 JVM 参数。
帮助!
TIA, 比尔
一个。 ProjectCommonUtil build.gradle
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.3/userguide/tutorial_java_projects.html
*/
// +++++++++++++++++++++ ORDER IS IMPORTANT ++++++++++++++++
plugins {
id 'base'
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
//apply plugin: 'checkstyle'
apply plugin: 'jdepend'
apply plugin: 'pmd'
apply plugin: 'project-report'
build.dependsOn('copyArcCommonProjectJar', 'copyArcCommonExternalJars')
group "com.mmm.arc"
version = '2.5.ArcCommon'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
main {
java {
srcDir 'src'
}
}
}
// Short hand form
//compileJava.doFirst { println 'In compileJava:BEGIN' }
//compileJava.doLast { println 'In compileJava:END' }
tasks.create(name: 'copyArcCommonProjectJar', type: Copy, dependsOn: 'jar') {
into "../CommonJars/ArcProjectJars"
from "${buildDir}/libs"
include "*.jar"
}
copyArcCommonProjectJar.doFirst {
println "${buildDir}:In copyArcCommonProjectJar:BEGIN"
// Remove existing jars only if build is necessary
delete "../CommonJars/ArcProjectJars/${name}*.jar"
}
copyArcCommonProjectJar.doLast { println 'In copyArcCommonProjectJar:END' }
//copyArcCommon.outputs.upToDateWhen { false }
tasks.create(name: 'copyArcCommonExternalJars', type: Copy, dependsOn: 'dependencies') {
into "../CommonJars"
from configurations.runtime
//include "*.jar"
}
copyArcCommonExternalJars.doFirst { println 'In copyArcCommonExternalJars:BEGIN' }
copyArcCommonExternalJars.doLast { println 'In copyArcCommonExternalJars:END' }
//copyExternalJars.outputs.upToDateWhen { false }
jar {
//baseName = 'ArcCommon'
}
jar.doFirst { println 'In jar:BEGIN' }
jar.doLast { println 'In jar:END' }
//jar.outputs.upToDateWhen { false }
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at implementation time
// implementation 'org.slf4j:slf4j-api:1.7.25'
// implementation 'org.slf4j:slf4j-api:+'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testimplementation dependency to testimplementation 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
// testimplementation 'junit:junit:4.12'
// providedimplementation is for jars need to build but are provided at runtime
// providedimplementation
}
d。 ProjectHttpClientUtil build.gradle
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.3/userguide/tutorial_java_projects.html
*/
// +++++++++++++++++++++ ORDER IS IMPORTANT ++++++++++++++++
plugins {
id 'base'
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
//apply plugin: 'checkstyle'
apply plugin: 'jdepend'
apply plugin: 'pmd'
apply plugin: 'project-report'
build.dependsOn(
'buildArcCommon',
'copyArcProjectJar', 'copyExternalJars'
)
group "com.mmm.arc"
version = '2.5.TekExHTTPClient'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
main {
java {
srcDir 'src'
}
}
}
task buildArcCommon(type: GradleBuild) {
doFirst {
println '--- Compiling ArcCommon ---'
buildFile = '../ArcCommon/build.gradle/'
}
// tasks = ['build']
}
tasks.create(name: 'copyArcProjectJar', type: Copy, dependsOn: 'jar') {
into "../CommonJars/ArcProjectJars"
from "${buildDir}/libs"
include "*.jar"
}
copyArcProjectJar.doFirst {
println 'In copyArcCommon:BEGIN'
// Remove existing jars only if build is necessary
delete "../CommonJars/ArcProjectJars/${name}*.jar"
}
copyArcProjectJar.doLast { println 'In copyArcCommon:END' }
//copyArcCommon.outputs.upToDateWhen { false }
tasks.create(name: 'copyExternalJars', type: Copy, dependsOn: 'dependencies') {
into "../CommonJars"
from configurations.runtime
//include "*.jar"
}
copyExternalJars.doFirst { println 'In copyExternalJars:BEGIN' }
copyExternalJars.doLast { println 'In copyExternalJars:END' }
//copyExternalJars.outputs.upToDateWhen { false }
//See above short hand
/*
task myTask ( ) {
println '+++++++++++++ Compiling ArcCommon BEGIN ++++++++++++++++'
}
*/
// Short hand form
/*
implementationJava.doFirst {
println '+++++++++++++ Compiling TekExHTTPClient BEGIN ++++++++++++++++'
// tasks = [ "buildArcCommon", "taskCopyAllTekExProjects" ]
// dependsOn buildArcCommon, taskCopyAllTekExProjects
}
implementationJava.doLast { println '+++++++++++++ Compiling TekExHTTPClient END ++++++++++++++++'}
//implementationJava.myTask
task taskCopyAllTekExProjects(type: Copy) {
into 'build/libs'
include '../ArcCommon/build/libs/*.jar'
}
//taskCopyAllTekExProjects.mustRunAfter 'buildArcCommon'
/*
task test(dependsOn: [implementation, implementationTest]) {
doLast {
println '+++++++++++++ Running ArcCommon Unit Tests ++++++++++++++++'
}
}
*/
/*
task dist(dependsOn: [implementation, test]) {
doLast {
println '+++++++++++++ Building ArcCommon Jar ++++++++++++++++'
}
}
*/
jar {
// baseName = 'TekExHTTPClient'
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at implementation time
implementation 'org.apache.httpcomponents:httpcore:+'
implementation 'org.apache.httpcomponents:httpclient:+'
compile fileTree (dir: '../CommonJars/ArcProjectJars')
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testimplementation dependency to testimplementation 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
// testimplementation 'junit:junit:4.12'
// providedimplementation is for jars need to build but are provided at runtime
// providedimplementation
}
【问题讨论】: