简体   繁体   English

如何使用gradle使GitLab CI发布Spring Boot JAR?

[英]How to make GitLab CI Release a Spring Boot JAR using gradle?

I have a Spring Boot project that builds using a bootJar task in gradle. 我有一个使用Gradle中的bootJar任务构建的Spring Boot项目。 It produces a runnable ____-1.0-SNAPSHOT.jar file. 它会生成一个可运行的____- 1.0-SNAPSHOT.jar文件。 Now, I want to leverage GitLab CI to build the JAR and make releases. 现在,我想利用GitLab CI来构建JAR并发布版本。

There didn't seem to be an obvious way to do the builds. 似乎没有明显的方法可以进行构建。 I started looking at the researchgate gradle plugin . 我开始研究researchgate gradle插件 It seems promising but has a lot of assumptions. 看起来很有希望,但有很多假设。

What is the best way to get the release JARs out of GitLab CI? 从GitLab CI中获取发布JAR的最佳方法是什么?

There is couple of ways of getting released artifacts from gitlab ci pipeline. 有几种方法可以从gitlab ci管道中获取发布的工件。

  1. Publish it to maven repository (private repository if it is propitiatory) 将其发布到Maven存储库(如果是私有的,则为私有存储库)
  2. use gitlab job artifact functionality within pipeline so you can download it via gitlab web interface 在管道中使用gitlab作业工件功能,因此您可以通过gitlab Web界面下载它
  3. build docker image from your pipeline and upload it to docker registry from pipeline 从您的管道构建docker映像并将其从管道上传到docker注册表

Here is the sample .gitlab-ci.yml which uses gitlab job artifacts functionality (assume gradle wrapper is used) 这是使用gitlab作业工件功能的示例.gitlab-ci.yml(假定使用gradle包装器)

image: java:8-jdk

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

build:
  stage: build
  script:
    - ./gradlew assemble
  # define path to collect artifacts
  artifacts:
    paths:
      - build/libs/*.jar
    expire_in: 1 week
  only:
    - master

Ruwanka provided a great answer, however I believe it is now a bit outdated. Ruwanka提供了一个很好的答案,但是我认为现在有点过时了。 GitLab.com (and self-hosted) now supports hosted maven repositories as a native feature of their Premium tiers. GitLab.com(和自托管)现在支持托管maven存储库,作为其Premium层的本机功能。

More information regarding how to deploy a java application (JAR, etc.) for private or public consumption can be found here: 在此处可以找到有关如何为私人或公共消费部署Java应用程序(JAR等)的更多信息:

https://docs.gitlab.com/ee/user/project/packages/maven_repository.html#gitlab-maven-repository-premium https://docs.gitlab.com/ee/user/project/packages/maven_repository.html#gitlab-maven-repository-premium

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在离线环境中使用 gradle 为 Spring 启动创建可执行 Jar - How to create an executable Jar for Spring Boot using gradle in an offline environment 如何使用 gradle 从 spring 引导应用程序生成 jar 文件? - How to generate jar file from spring boot application using gradle? Spring Boot + Gradle:如何构建可执行jar - Spring Boot + Gradle: how to build executable jar 使用 Gitlab CI 将 Spring 引导应用程序部署到 Google App Engine? - Deploy Spring Boot application to Google App Engine using Gitlab CI? 如何使用Spring Boot制作非可执行库(jar)? - How to make non executable library (jar) using spring boot? 带有依赖项的Jar Spring Boot Gradle - Jar with dependencies spring boot gradle 如何使用Gradle在Spring Boot中覆盖Thymeleaf 1.5.8.RELEASE的传递依赖Groovy版本 - How to overwrite version of transitive dependency Groovy from Thymeleaf 1.5.8.RELEASE in Spring Boot using Gradle 如何使用Gradle制作多版本JAR文件? - How to make Multi-Release JAR Files with Gradle? 使用 gradle 在 spring boot jar 中排除 application.properties - Exclude application.properties inside spring boot jar using gradle 使用Gradle应用程序插件使用重新打包的Spring Boot jar创建发行版 - Creating distribution with repackaged spring boot jar using gradle application plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM