gradle使用插件将jar包以及源码打入nexus的maven私服

news/2024/5/20 1:39:19 标签: gradle, java, sourceJar

之前写过一篇文章https://blog.csdn.net/u011943534/article/details/89173294,使用gradle的maven-publish插件将源码打成jar并推送至了maven私服。现在想让源码也打入maven私服,方便查看源码。实现方式很简单,只需做一点修改。

1、添加sourceJar Task

java">task sourcesJar(type: Jar) {
        from sourceSets.main.allJava
        archiveClassifier = 'sources'
    }

2、推送

java">task sourcesJar(type: Jar) {
        from sourceSets.main.allJava
        archiveClassifier = 'sources'
    }

3、完整例子:

java">
buildscript {
    repositories {
        maven { url "${nexusUrl}" }
        maven {url "${aliyunUrl}"}
        maven { url "${springUrl}" }
        maven { url "${spring2Url}" }
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("com.google.protobuf:protobuf-gradle-plugin:${gradleProtobufGenerateVerson}")
//        classpath "se.transmode.gradle:gradle-docker:${gradle_docker_version}"
    }
}

subprojects  {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'idea'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'maven'
    apply plugin: 'maven-publish'
    group = 'com.iscas'
    //版本号定义规则:开发中: <版本号(x.x.x)>-<当天日期>-<当天更新的小序号>
      //发布版本:x.x.x-RELEASE
    version = '1.0.1-2021.01.23-3'
    sourceCompatibility = "${javaVersion}".toFloat()
    targetCompatibility = "${javaVersion}".toFloat()

    repositories {
        maven { url "${nexusUrl}" }
        maven {url "${aliyunUrl}"}
        maven { url "${springUrl}" }
        maven { url "${spring2Url}" }
        maven { url "${spring3Url}" }
        jcenter()
        mavenCentral()
    }
    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
    }
    dependencies {
        annotationProcessor "org.projectlombok:lombok"
        compileOnly "org.projectlombok:lombok"
        testAnnotationProcessor "org.projectlombok:lombok"
        testCompileOnly "org.projectlombok:lombok"
        //junit
        testCompile group: 'junit', name: 'junit', version:"${junitVersion}"
    }
    //这里一定得要。在多模块下,不然编译失败,因为不会把依赖模块给打包。
    jar {
        enabled = true
    }

    task sourcesJar(type: Jar) {
        from sourceSets.main.allJava
        archiveClassifier = 'sources'
    }
    //上传至nexus
    publishing {
        publications {
            maven(MavenPublication) {
                groupId project.group
                artifactId project.name
                version project.version
                //若是war包,就写components.web,若是jar包,就写components.java
                from components.java
//                artifact shadowJar
                artifact sourcesJar
            }
        }
        repositories {
            maven {

                if (project.version.endsWith('-SNAPSHOT')) {
                    url = "http://172.16.10.190:8081/repository/maven-snapshots/"
                } else {
                    url = "http://172.16.10.190:8081/repository/maven-releases/"
                }

                credentials {
                    username 'xxx'
                    password 'xxx'
                }
            }
        }
    }
}

http://www.niftyadmin.cn/n/1302371.html

相关文章

springboot学习(三十八) springboot多种方式注册过滤器

github地址&#xff1a;https://github.com/zhuquanwen/springboot-filter-listener-samples.git 1、使用WebFilter注解 像在servlet中一样&#xff0c;可以使用WebFilter注册一个过滤器 package com.iscas.springboot.filter.samples.filter1;import javax.servlet.*; impor…

istio学习(一) 离线部署istio

前提必须部署k8s&#xff0c;这里我的k8s版本是1.52.1,istio版本使用的1.5.5 一、准备istio离线包 1、下载istio 下载&#xff1a;https://github.com/istio/istio/releases/download/1.5.5/istio-1.5.5-linux.tar.gz 2、下载镜像 docker pull istio/proxyv2:1.5.5 docker pu…

Nginx学习(十二) 将前端包打入nginx镜像并实现后端反向代理

1、准备一个测试的前端包 这里使用dist 2、编写nginx.conf.template BACKEND_URL是一个环境变量&#xff0c;从外部传入 user nginx;worker_processes 1; error_log logs/error.log error; pid logs/nginx.pid;events {worker_connections 1024; }http {include mime.…

springboot学习(三十九) springboot多种方式注册监听器

github地址&#xff1a;https://github.com/zhuquanwen/springboot-filter-listener-samples.git 1、在启动类注册 import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener;/**** author zhuquanw…

测试CompletableFutrue的使用

很多场景下&#xff0c;获取线程运行的结果&#xff0c;使用execute方法去提交任务是无法获得结果的&#xff0c;这时候会改用submit方法去提交&#xff0c;以便获得线程运行的结果。 而submit方法返回的就是Future&#xff0c;一个未来对象。 使用future.get() 方法去获取线程…

Integer类所有的静态函数测试

使用的JDK版本为11 package com.iscas.common.tools.jdk;import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4;/*** Integer 静态方法测试** author zhuquanwen* vesion 1.0* date 2021/2/3 20:48* since jdk1…

k8s学习(二十九) k8s中部署kube-keepalived-vip

在当前的kubernetes群集中使用service为每个节点上分配一个端口&#xff08;相同的端口&#xff09;&#xff0c;并将通过该端口的流量代理到端点。问题是它不能提供高可用性&#xff0c;因为需要事先知道正在运行的节点的IP地址&#xff0c;并且在发生故障的情况下&#xff0c…

springboot学习(四十) springboot下rsocket的使用

RSocket RSocket是一个二进制的协议&#xff0c;以异步消息的方式提供4种对等的交互模型&#xff0c;以字节流的方式运行在TCP, WebSockets, Aeron等传输层之上。RSocket专门设计用于与Reactive风格应用配合使用&#xff0c;这些应用程序基本上是非阻塞的&#xff0c;并且通常&…