gpt4 book ai didi

gradle - 从Gradle将jar和来源jar发布到Artifactory

转载 作者:行者123 更新时间:2023-12-03 20:30:08 25 4
gpt4 key购买 nike

这是我的build.gradle:

buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "admin"
password = "password"
}
name = "maven-main-cache"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}

apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'codenarc'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"

version="0.0.2"
group = "mylib"

repositories {
mavenCentral()
add buildscript.repositories.getByName("maven-main-cache")
maven {
url "http://localhost:8081/artifactory/myapp-snapshots"
}
}

dependencies {
compile 'commons-validator:commons-validator:1.4.0'
testCompile 'junit:junit:4.11'
}

artifactory {
contextUrl = "http://localhost:8081/artifactory"
publish {
repository {
repoKey = 'myorg-snapshots'
username = "admin"
password = "password"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives sourcesJar
}

task dist(type: Zip, dependsOn: build) {
classifier = 'buildreport'

from('build/test-results') {
include '*.xml'
into 'tests'
}

from('build/reports/codenarc') {
into 'reports'
}

from('build/docs') {
into 'api'
}

from(sourcesJar) {
into 'source'
}

from('build/libs') {
exclude '*-sources.jar'
into 'bin'
}
}

基于当前设置:
  • 要构建我的JAR,我必须先运行gradle clean build groovydoc sourcesJar dist,然后再运行
  • 要发布到Artifactory,我必须运行gradle artifactoryPublish的第二个命令

  • 我要在此处更改的两件事:
  • gradle artifactoryPublish仅将我构建的JAR和动态创建的POM发布到Artifactory。我还希望它发布我的构建正在创建的源JAR。 怎么样? ;和
  • 理想情况下,我希望能够通过仅调用gradle publish来完成上述所有操作,而不必依次运行这两个命令。 这可能吗?如果是这样,怎么办?
  • 最佳答案

    在发布源代码时,您需要通过以下方式修改脚本:

    publishing {
    publications {
    mavenJava(MavenPublication) {
    from components.java
    artifact (sourcesJar) {
    classifier = 'sources'
    }
    }
    }
    }

    当涉及到单个命令时,您需要定义任务之间的依赖关系。不幸的是,我无法尝试该脚本,因此它可能是多余的,但应该可以完成工作:
    artifactoryPublish.dependsOn('clean', 'build', 'groovydoc', 'sourcesJar', 'dist')
    publish.dependsOn(artifactoryPublish)

    关于gradle - 从Gradle将jar和来源jar发布到Artifactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27047564/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com