Gradle,从多个依赖项创建和复制javadoc jar

时间:2016-06-29 10:39:54

标签: gradle

我有以下项目结构:

  • 项目1
  • 项目2取决于项目1
  • 项目3取决于项目1

(也有外部依赖)

我使用

创建源jar和javadoc jar
task sourcesJar(type: Jar) {
    destinationDir = file("./../../build/export/$project.name")
    classifier 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    destinationDir = file("./../../build/export/$project.name")
    classifier 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

现在我需要创建一个文件夹,其中包含项目的jar文件和所有依赖项的jar文件。我目前的版本是

task makeLibsDir(type: Copy, dependsOn: ['jar', 'sourcesJar', 'javadocJar']) {
   description 'Builds all relevant jar files to use this project as dependency and copies them to the libs folder'

   from jar // copying from jar configuration

   File outdir = file("./../../build/$project.name/libs/")
   outdir.mkdirs()
   into outdir

   into('/') {
          from configurations.runtime
  }
}

当我调用project2:makeLibsDir时,我得到一个包含

的文件夹

project1.jar project2.jar extDept1.jar ...

但有两个问题

  • 来自jar的源jar和javadoc jar不是构建
  • 来自jar的源jar和javadoch jar是构建的,但没有复制到libs文件夹

任何想法我怎么能

  1. 确保所有依赖项目的所有jar都已构建
  2. 将它们复制到最终位置
  3. 编辑:Full build.gradle的最小化版本

    buildDir = "../build/$project.name"
    
    subprojects {
    apply plugin: 'java'
    apply plugin: 'application'
    apply plugin: 'eclipse'
    
    repositories {
        mavenCentral()
    }
    
    sourceSets {
           ....         
    }
    
    jar {
         destinationDir = file("./../../build/export/$project.name")
           destinationDir.mkdirs()
         baseName = project.name            
    }
    
    
      task makeLibsDir(type: Copy, dependsOn: ['jar', 'sourcesJar', 'javadocJar']) {
    
          from jar
    
          File outdir = file("./../../build/$project.name/libs/")
          outdir.mkdirs()
          into outdir
    
          into('/') {
                 from configurations.runtime
         }
       }
    
       task sourcesJar(type: Jar) {
              destinationDir = file("./../../build/export/$project.name")
           classifier 'sources'
           from sourceSets.main.allSource
       }
    
       task javadocJar(type: Jar, dependsOn: javadoc) {
          destinationDir = file("./../../build/export/$project.name")
          classifier 'javadoc'
          from javadoc.destinationDir
       }
    
       artifacts {
           archives sourcesJar
           archives javadocJar
       }
    
          project(':project1') {
            dependencies {
              ...
            }
          }
    
          project(':project2') {
            dependencies {
                ...
                compile project(':project1')  
            }
          }
    
          project(':project2') {
            dependencies {
                  ...
                  compile project(':project1')  
            }
          }
     }
    

0 个答案:

没有答案