【问题标题】:Gradle: Create single JAR with all dependenciesGradle:创建具有所有依赖项的单个 JAR
【发布时间】:2018-06-30 02:20:19
【问题描述】:

我有 project1 和 project2。

project1 依赖于 project2:

dependencies {
    api project(':project2')
}

有什么方法可以得到一个包含 project1 和 project2 的类的 jar 文件?

【问题讨论】:

    标签: android gradle jar


    【解决方案1】:

    试试这个任务:

    task jar(type: Jar) {
     baseName="project"
     from 'src/main/java'
    }
    task create(type: Jar) {
      baseName = "project1"
      from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
      }
      with jar
    }
    
    configurations {
      jarConfig
    }
    
    artifacts {
      jarConfig jar
    }
    

    【讨论】:

      【解决方案2】:

      当然是的:

      // Make your project 2 api configuration
      configurations {
          api
          compile.extendsFrom(api)
      
      }
      
      dependencies {
          api project(':project2')
      }
      
      task packAllToJar (type : Jar){
          // pack yours main module
          from sourceSets.main.output
      
          // pack your other "api" module dependencies
          from {
              configurations.api.collect { it.isDirectory() ? it : zipTree(it) }
          }
      
          // pack all dependencies in the root project
          from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
      
          // Set name and version
          version = "1.0"
          baseName = "customJarName"
      }
      

      【讨论】:

        猜你喜欢
        • 2020-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-01
        • 2021-03-12
        • 1970-01-01
        • 2014-09-11
        • 1970-01-01
        相关资源
        最近更新 更多