Gradle上传如何真正起作用? [英] How do Gradle Uploads Really Work?

查看:103
本文介绍了Gradle上传如何真正起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在这个脚本中的意图很简单:我在使用Gradle时创建并上传一个工件。想要下载一个源代码压缩包和可能的一堆依赖项,运行一个build.shshell脚本,最终创建一个二进制压缩包,并让gradle脚本将其发布到一个工件回购站。



主要思想是,我可以使用gradle的依赖管理,maven工件知识以及构建并行和避免来控制构建脚本本身的执行,主要是管理我的第三方二进制依赖关系...



以下脚本失败时发生400错误,我怀疑这是因为我没有将工件链接到实际的输出文件。



什么是正确的方法?

apply plugin:'maven '

version'testarch-4.2'

repositories {
maven {
urlhttp:// nexus / ...
}
}

配置{
sourceArchive
binaryArchive
}

依赖关系{
sourceArchiveorg.gnu:bash:4.2:src @ tgz
}

任务buildFromSource(类型:Exec){
inputs.files configurations.sourceArchive.files
outputs.file文件($ {project.name} - $ {project.version} .tgz )
executable'./build.sh'
def myArgs = configurations.sourceArchive.files.path
myArgs.add(0,outputs.files.asPath)
args myArgs
}

artifacts {
//是否真的是将单例集合
//转换为单例的唯一方法?
// def outputFile
// buildFromSource.outputs.files.each {outputFile = it}
// Nope:这是更好的魔术:
def outputFile = buildFromSource.outputs。 files.singleFile
println outputFile.path
binaryArchive file:outputFile,name:'bash'
// binaryArchive file:file(buildFromSource.outputs.files.asPath),name:'bash'
}

uploadArchives {
configuration = configurations.binaryArchive
repositories.mavenDeployer {
repository(url:http:// nexus / .. ){
authentication(userName:me,password:secret!)
}
pom.groupId ='org.gnu'
}
}

uploadArchives.dependsOn buildFromSource

我得到的错误是:

  *出错:
任务':uploadArchives'的执行失败。
>无法发布配置'binaryArchive'
>部署工件时出错'org.gnu:bash:tgz':部署工件时出错:未能传输文件:http://nexus/.../org/gnu/bash/testarch-4.2/bash-testarch-4.2.tgz。返回代码是:400

从评论更新,同样的错误 - 尝试访问nexus日志进一步调试。



来自Nexus的错误是缺少实体,请参阅:缺少请求实体对PUT到Nexus的响应

解决方案

我的问题的根本原因是我正在测试一个空文件。 Nexus不喜欢空文件。只要我把内容放进去,Nexus很高兴,而且代码正在工作。

I'm having some real problems understanding how all the pieces in gradle to create and upload an artifact fit together.

My intention in this script is simple: I want to download a source tarball and possibly a bunch of dependencies, run a "build.sh" shellscript which will end up creating a binary tarball and have the gradle script publish it to an artifact repo.

The main idea is that I can use gradle's dependency management, maven artifact knowledge and build parallelization and avoidance to control the execution of the build scripts themselves, mainly to manage my set of third party binary dependencies...

The following script fails with a 400 error, I suspect it's because I'm not linking the artifact with the actual output file.

What's the right and proper way to go?

apply plugin: 'maven'

version 'testarch-4.2'

repositories {
  maven {
    url "http://nexus/..."
  }
}

configurations {
  sourceArchive
  binaryArchive
}

dependencies {
  sourceArchive "org.gnu:bash:4.2:src@tgz"
}

task buildFromSource(type: Exec) {
  inputs.files configurations.sourceArchive.files
  outputs.file file("${project.name}-${project.version}.tgz")
  executable './build.sh'
  def myArgs = configurations.sourceArchive.files.path
  myArgs.add(0, outputs.files.asPath)
  args myArgs
}

artifacts {
  // Is this really the only way to transform a singleton collection
  // into the singleton?
  //   def outputFile
  //   buildFromSource.outputs.files.each { outputFile = it }
  // Nope: this is better magic:
  def outputFile = buildFromSource.outputs.files.singleFile
  println outputFile.path
  binaryArchive file: outputFile, name: 'bash'
  // binaryArchive file: file(buildFromSource.outputs.files.asPath), name: 'bash'
}

uploadArchives {
  configuration = configurations.binaryArchive
  repositories.mavenDeployer {
    repository(url: "http://nexus/..") {
      authentication(userName: "me", password: "secret!")
    }
    pom.groupId = 'org.gnu'
  }
}

uploadArchives.dependsOn buildFromSource

The error I get is:

* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'binaryArchive'
   > Error deploying artifact 'org.gnu:bash:tgz': Error deploying artifact: Failed to transfer file: http://nexus/.../org/gnu/bash/testarch-4.2/bash-testarch-4.2.tgz. Return code is: 400

Updated from comments, same error - trying to get access to the nexus logs for further debugging.

Error from Nexus is "missing entity", see: Missing Request Entity response to a PUT to Nexus

解决方案

The root cause of my problem was I was testing with an empty file. Nexus doesn't like empty files. As soon as I put content in it, Nexus was happy and the code was working.

这篇关于Gradle上传如何真正起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆