将多项目本身添加为另一个项目中的依赖项

Add multi project itself as a dependency in another project

找了好久,最后选择这里养!在eclipse中,我正在使用Gradle设计这样的项目结构,如下图...

Algorithms              //Parent Project
    -SubModuleCore      //Child Project for common utilities & dependencies
        -build.gradle
    -SubModuleOne       //Child project for any operation
        -build.gradle   //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
    -SubModuleTwo       //Child project for another operation
        -build.gradle   //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
    -build.gradle
    -settings.gradle

Services                //Stand-Alone project
    -build.gradle       //Here I want to add 'Algorithms' as a single dependency
    -settings.gradle

eclipse 工作中的项目结构相同-space 如上所示。我能够生成 .jarAlgorithms 项目。所以问题是我想将此 Algorithms 项目添加为项目 Services 中的单个依赖项,例如 compile project(':Algorithms')。但是 eclipse 只是说 'shut-up!'。我不想将它发布到像 maven central / jitpack 等地方,而是我想在本地进行。我正在尝试这种方式...

Services/build.gradle

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
project.webAppDirName = 'WebContent'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'lib', include: ['*.jar'])
    compile project(':Algorithms')
}

Services/settings.gradle

rootProject.name = 'Services'
include 'Algorithms'
project(':Algorithms').projectDir = new File(settingsDir, '../Algorithms')

Algorithms/build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = "1.8";
targetCompatibility = "1.8";

subprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'

    sourceCompatibility = "1.8";
    targetCompatibility = "1.8";

    buildscript {
       dependencies {
          repositories {
            jcenter()
             mavenCentral()
          }
        }
    }

    repositories {
        jcenter()
        mavenCentral()
    }

}
subprojects.each { subproject -> 
   evaluationDependsOn(subproject.path) 
}
jar.dependsOn subprojects.tasks['classes']
jar {
  baseName = 'algorithms'
  subprojects.each { subproject ->
    from subproject.sourceSets.main.output.classesDir
  }
  from files('resources/log4j2.xml')
  from files('resources/application.properties')
}

Algorithms/settings.gradle

rootProject.name = 'Algorithms'
include ':SubModuleCore', ':SubModuleOne', ':SubModuleTwo'

我尝试了SO的几种解决方案,仍然没有成功。有人请帮助我,我在这里被困得很厉害。貌似和这个很接近了,不知道还差什么!

谢谢

您可以使用 includeBuild 功能。

在 Services/settings 中声明包含的构建。gradle

rootProject.name='Services'

includeBuild '../Algorithms'

然后使用

表达依赖关系
compile "${project.group}:${project.name}"

将算法项目中的项目分组并命名。