Gradle任务未运行

问题描述

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

项目的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'
  }
}

模块的build.gradle

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'
  }

}

生成的日志: 跳过任务:':module:build',因为它没有任何动作。

在阅读了如下关于stackoverflow的答案后,我试图修改task.register,但是它不起作用:

tasks.register("projectDistribution",Zip) {
  group = 'build'
  dependsOn jar
  archiveName = 'myProject.zip'
  duplicatesStrategy 'exclude'
  doFirst{
    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'
  }
 }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...