1. 进入阿里云的maven仓库,将以下密码、用户名和url复制到公共项目的build.gradlew中填充(就是下面的java代码).(注意使用的是不是生产库,举例使用的生产库不是快照,release是生产,snapshot是快照)List item
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId = "$project.group"
                artifactId = "demo"
                version = "$project.version"
                from components.java

                versionMapping {
                    usage('java-api') {
                        fromResolutionOf('runtimeClasspath')
                    }
                    usage('java-runtime') {
                        fromResolutionResult()
                    }
                }
            }
        }

        repositories {
            maven {
                allowInsecureProtocol true
                url = 'xxxxxxx'
                credentials {
                    username = 'xxxxxx'
                    password = 'xxxxxx'
                }
            }
        }
    }
}
  1. 此外还需添加jar的处理方式,否则报错
bootJar {
    enabled = false
}

jar {
    enabled = true
}
  1. 其他项目引用该jar包,引用格式
allprojects {
    repositories {
        maven {
            credentials {
                username = 'xxxxxxx'
                password = 'xxxxxx'
            }
            url = 'xxxxxxx'
        }
        //放其他的仓库
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/spring/'}
    }
}
  1. 在plugins中加上** id 'maven-publish'**
  2. 流水线上构建上传时执行 ./gradlew build 和 ./gradlew publish
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐