How to build Groovy JAR w/ Gradle and publish it to in-house repo

后端 未结 2 1717
你的背包
你的背包 2021-01-05 12:41

I have a Groovy project and am trying to build it with Gradle. First I want a package task that creates a JAR by compiling it against its dependencies. Then I n

2条回答
  •  春和景丽
    2021-01-05 13:27

    You're more than welcome to use artifactory plugin for that. The documentation can be found in our user guide and below you can find a full working example of gradle build.

    Run gradle build artifactoryPublish to build and publish the project.

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
        }
    }
    apply plugin: 'java'
    apply plugin: 'maven-publish'
    apply plugin: 'com.jfrog.artifactory'
    
    group = 'com.jfrog.example'
    version = '1.2-SNAPSHOT'
    status = 'SNAPSHOT'
    
    dependencies {
        compile 'org.slf4j:slf4j-api:1.7.5'
        testCompile 'junit:junit:4.11'
    }
    
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }
    
    publishing {
        publications {
            main(MavenPublication) {
                from components.java
                artifact sourcesJar
        }
    }
    
    artifactory {
        contextUrl = 'http://myartifactory/artifactory'
        resolve {
            repository {
                repoKey = 'libs-release'
            }
        }
        publish {
            repository {
                repoKey = 'libs-snapshot-local'
                username = 'whatever'
                password = 'whatever123'
            }
            defaults {
                publications 'main'
            }
        }
    }
    

提交回复
热议问题