使用 gradle 将 jar 以外的东西发布到 Nexus

Publish something else than a jar with gradle to Nexus

我正在尝试结合使用 Gradle 和 Ant 来构建我们的 OpenEdge 项目。 OpenEdge 是几个世纪前的一种 4GL 语言。 ;-)

无论如何,我已经设法下载了一些 jar 依赖项,但现在我陷入了如何将 PL 文件(进度库)发布到 Nexus 存储库的问题。问题是,像 Maven 一样,Gradle 似乎也是为 Java 项目制作的。

这是我的脚本(我还有一个 settings.gradle 文件 rootProject.name = 'stomp'):

apply plugin:'java'
apply plugin: 'maven-publish'

group 'be.mips'
version = '1.4.0-SNAPSHOT'

repositories {
  /*
  Gradle uses the same logic as Maven to identify the location of your local
  Maven cache. If a local repository location is defined in a settings.xml,
  this location will be used. The settings.xml in USER_HOME/.m2 takes precedence
  over the settings.xml in M2_HOME/conf. If no settings.xml is available, Gradle
  uses the default location USER_HOME/.m2/repository.
  */
  mavenLocal()
  maven {
    credentials {
      username '****'
      password '****'
    }
    url "http://srv-ci-nexus:8082/nexus/content/repositories/MadeApplReleases/"
    url "http://srv-ci-nexus:8082/nexus/content/repositories/MadeApplSnapshots/"
  }
  mavenCentral()
}

def stompProgressLibraryFile = file('dist/lib/STOMP.PL')

artifacts {
  archives stompProgressLibraryFile
}

publishing {
  publications {
    mavenJava(MavenPublication) {
      from components.java
      artifact stompProgressLibraryFile
    }
  }

  repositories {
    maven {
      // default credentials for a nexus repository manager
      credentials {
        username '****'
        password '****'
      }
      // url to the releases maven repository
      url "http://srv-ci-nexus:8082/nexus/repositories/snapshots"
    }
  }
}

configurations {
  antconf
}

dependencies {
  antconf 'be.mips:mips-progress-ant-tasks:1.5.8-SNAPSHOT',
  'be.mips:mips-pct:1.0-SNAPSHOT',
  'ant-contrib:ant-contrib:1.0b3'
}

/* Loads the jars */
ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
configurations.antconf.each {
  File f -> antClassLoader.addURL(f.toURI().toURL())
}

/* Extend clean task */
clean.doFirst {
  delete '_ant_rcode', 'src', 'dist'
  println 'deleted directories'
}

/* Create dist/lib directory as prolib does not create directory automatically */
task init(dependsOn: clean) {
  doLast{
    project.file('dist/lib').mkdirs()
    println 'created dist/lib'
  }
}

ant.importBuild 'build.xml'

运行ning gradle publish 给我下一个输出:

C:\Workspace\git-repositories\OpenEdge\stomp.git>gradle -DDLC=C:\OpenEdge6\DLC publish :generatePomFileForMavenJavaPublication :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar UP-TO-DATE :publishMavenJavaPublicationToMavenRepository Could not find metadata be.mips:stomp:1.4.0-SNAPSHOT/maven-metadata.xml in remote (http://srv-ci-nexus:8082/nexus/repositories/snapshots) Upload http://srv-ci-nexus:8082/nexus/repositories/snapshots/be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.pom Could not transfer artifact be.mips:stomp:pom:1.4.0-20161227.115652-1 from/to remote (http://srv-ci-nexus:8082/nexus/repositories/snapshots): Could not write to resource 'be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.pom' Upload http://srv-ci-nexus:8082/nexus/repositories/snapshots/be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.jar Could not transfer artifact be.mips:stomp:jar:1.4.0-20161227.115652-1 from/to remote (http://srv-ci-nexus:8082/nexus/repositories/snapshots): Could not write to resource 'be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.jar' Upload http://srv-ci-nexus:8082/nexus/repositories/snapshots/be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.pl Could not transfer artifact be.mips:stomp:pl:1.4.0-20161227.115652-1 from/to remote (http://srv-ci-nexus:8082/nexus/repositories/snapshots): Could not write to resource 'be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.pl' :publishMavenJavaPublicationToMavenRepository FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':publishMavenJavaPublicationToMavenRepository'.

    Failed to publish publication 'mavenJava' to repository 'maven' Failed to deploy artifacts: Could not transfer artifact be.mips:stomp:pom:1.4.0-20161227.115652-1 from/to remote (http://srv-ci-nexus:8082/nexus/repositories/snapshots): Could not write to resource 'be/mips/stomp/1.4.0-SNAPSHOT/stomp-1.4.0-20161227.115652-1.pom'

  • 尝试:运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。

构建失败

总时间:1.089 秒

我注意到的第一件事是有这些 java 我不需要的任务。 :compileJava, :processResource, :类, :jar ...

基本上我有一个 build.xml ant 文件来做我想做的一切。但是ant中的依赖管理很差。所以我决定结合使用 Gradle 和 Ant。我希望 Gradle 为我做依赖管理。到目前为止,下载依赖项似乎工作正常(必须尝试使用​​ PL 而不是 jar)。但是发布 jar 以外的东西,你是怎么做到的?

阅读了大量 Gradle 在线文档,但所有示例似乎都基于 java。

如果您不需要编译 java 代码,请使用 base 插件而不是 java。你也应该删除 from components.java:

apply plugin: 'base'
apply plugin: 'maven-publish'

publishing {
  publications {
    mavenJava(MavenPublication) {
      artifact stompProgressLibraryFile
    }
  }
}

您的下一个错误 "Could not write to resource" 很可能不是 gradle 问题,请检查对存储库的写入权限。在发布到远程仓库之前,先尝试在本地仓库发布:

应用插件:

apply plugin: "maven"

执行任务install:

$ ./gradlew install