本文已参与「新人创作礼」活动,一起开启掘金创作之路
1. 上传jar
- 创建仓库
1.1 创建工程
- 这里创建了一个新的gradle工程,只有一个util文件,用来后续测试使用
1.2 修改build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
plugins {
id 'java'
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
group 'org.example'
version '1.1'
repositories {
mavenCentral()
}
dependencies {
}
test {
useJUnitPlatform()
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
archiveClassifier = 'javadoc'
}
artifactory {
contextUrl = 'http://127.0.0.1:8082/artifactory'
publish {
repository {
repoKey = 'fisher-gradle-release' // The Artifactory repository key to publish to
username = "admin" // The publisher user name
password = "AP31jMy61H78ScCYE2ki1jRDaoB" // The publisher password
}
defaults {
// Reference to Gradle publications defined in the build script.
// This is how we tell the Artifactory Plugin which artifacts should be
// published to Artifactory.
publications('mavenJava')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team' : 'core']
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// 生成源码包
artifact sourcesJar
// 生成javadoc包
artifact javadocJar
}
}
}
1.3 发布
- 在Terminal下,执行
gradle artifactoryPublish命令
- 如果要生成javadoc包,注释需要满足javadoc标准,否则发布时会报错
2. 下载jar
- 这里新建了一个gradle项目,在项目中使用时,在build.gradle文件中添加下面代码
plugins {
id 'org.springframework.boot' version '2.6.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven {
url "http://127.0.0.1:8082/artifactory/fisher-gradle-release"
// 如果需要密码登录,添加下面代码
// credentials {
// username = "admin"
// password = "AP31jMy61H78ScCYE2ki1jRDaoB"
// }
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.example', name: 'demo', version: '1.1'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
tasks.named('test') {
useJUnitPlatform()
}
- 使用jar内的方法