gradle - 将带有gradle的jar以外的其他内容发布到Nexus

标签 gradle ant nexus progress-4gl openedge

我正在尝试将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'

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

C:\Workspace\git-repositories\OpenEdge\stomp.git>gradle -DDLC=C:\OpenEdge\116\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,:classes,: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
    }
  }
}

您的下一个错误“无法写入资源”很可能不是gradle问题,请检查对存储库的写入权限。在发布到远程存储库之前,请尝试将其发布在本地存储库中:

应用插件:
apply plugin: "maven"

执行任务install:
$ ./gradlew install

关于gradle - 将带有gradle的jar以外的其他内容发布到Nexus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41344808/

相关文章:

android - 启用 Android 零售演示

gradle - 具有非标准文件夹层次结构的多个项目Gradle构建

spring - 为自定义输出文件夹和exe名称自定义gradle脚本

java - 使用 Ant : ClassNotFoundException: org. junit.Test 运行 Android JUnit 测试

java - 运行 jar 文件时包含外部 Jar

未更新来自 nexus 快照存储库的 Gradle 更改模块

maven - 在 Gradle 项目中构建 Maven 子模块

android - 如何在 gradle 上添加我的框架

java - NetBeans IDE 6.7.1 Ant 脚本变量

maven - Nexus3:将特定的Maven存储库移至另一个Blob存储区