zip文件未在gradle生成中生成

yrwegjxp  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(255)

我的gradle项目有多个模块。我希望所有的源代码jar和依赖项jar都在lib文件夹中,并且应该压缩以上传到存储库中。我已经按照我(新手)的理解编写了代码,但我不知道为什么它不起作用。

myProject's build.gradle

apply plugin: 'idea'
apply plugin: 'distribution'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'

tasks.register("projectDistribution", Zip) {
  group = 'build'
  dependsOn jar
  archiveName = 'myProject.zip'
  duplicatesStrategy 'exclude'
  project.getTasksByName('distZip', true).each{task ->
     dependsOn task
     task.enabled = false
     task.archiveName = task.project.name
     with task
  }

  from (jar){
    into 'myProject/lib'
  }

  from(sourceSets.main.runtimeClasspath.files.findAll {it.name.endsWith('jar') }.collect { it }) {
    into 'myProject/lib'
  }

  from(sourceSets.main.runtimeClasspath.files.findAll {it.name.endsWith('jar') }.collect { zipTree(it) }) 
  {
    into 'myProject/lib'
  }

buildscript{
  repositories {
    maven {
      url uri('http://myRepoUrl')
    }
  }
  dependencies {
    classpath 'io.spring.grale:dependency-management-plugin:1.0.7.RELEASE'
  }
}

这是我模块的gradle.build文件

buildscript{
  repositories {
    maven {
      url uri('http://myRepoUrl')
    }
  }
  dependencies {
    classpath 'com.google.guava:guava:27.1-jre'
  }
}

plugin{
  id 'java'
}

repositories{
  mavenCentral()
}

dependencies {
  compile project(":myModule2")
  compile 'com.google.guava:guava:27.1-jre'
}

task distZip(type: Zip, dependsOn: [ jar ]) {
  baseName = 'myProject'
  duplicatesStrategy 'exclude'

  from (jar){
    into 'myProject/lib'
  }

  from(sourceSets.main.runtimeClasspath.files.findAll {it.name.endsWith('jar') }.collect { it }) {
    into 'myProject/lib'
  }

}

据我所知,这段代码应该在构建中创建一个distributions文件夹,其中应该有一个包含所有jar的zip文件。但我看不到分发文件夹本身。你能引导我理解我的错误吗。
如果您对此有任何建议,我们将不胜感激!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题