No artifacts will be uploaded to artifactory(jfrog) repository

Hello,

we use artifactory as repository, we have the issue that only the build info will be uploaded but no artifacts.


buildscript {
    ext.cubaVersion = '6.5.5'
    repositories {
        jcenter()
        maven {
            url "${uploadUrl}"
            credentials {
                username("${artifactory_user}")
                password("${artifactory_password}")
            }
        }
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }
        maven {
            url 'https://repo.cuba-platform.com/content/groups/premium'
            credentials {
                username(rootProject.hasProperty('premiumRepoUser') ? rootProject['premiumRepoUser'] : System.getenv('CUBA_PREMIUM_USER'))
                password(rootProject.hasProperty('premiumRepoPass') ? rootProject['premiumRepoPass'] : System.getenv('CUBA_PREMIUM_PASSWORD'))
            }
        }        
    }

    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"

        //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
    }
}

allprojects {
    apply plugin: "com.jfrog.artifactory"
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }
    }
    resolve {
        repository {
            repoKey = 'gradle-dev'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
    }
}

Has anyone a solution how to upload the built artifacts?

Hello Mike,

here it is an example based on CUBA Platform 6.4.2. Just double checked right now, it should work.

gradle artifactoryPublish
:generatePomFileForMavenJavaPublication
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:artifactoryPublish
Deploying artifact: http://192.168.*.*:8081/artifactory/gradle-release/com/company/cubasampleboard/cuba-sample-board/0.1-SNAPSHOT/cuba-sample-board-0.1-SNAPSHOT.jar
Deploying artifact: http://192.168.*.*:8081/artifactory/gradle-release/com/company/cubasampleboard/cuba-sample-board/0.1-SNAPSHOT/cuba-sample-board-0.1-SNAPSHOT.pom
Deploying build descriptor to: http://192.168.*.*:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://192.168.*.*:8081/artifactory/webapp/builds/cuba-sample-board/1500382883997

BUILD SUCCESSFUL

Let me know if this was helpful for you.

Best regards,
Ivan


build.gradle:


buildscript {
    ext.cubaVersion = '6.4.2'
    repositories {
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"

        classpath "com.haulmont.cuba:cuba-global:$cubaVersion"

        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.18"
    }
}

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

def globalModule = project(':board-global')
def coreModule = project(':board-core')
def guiModule = project(':board-gui')
def webModule = project(':board-web')

def servletApi = 'org.apache.tomcat:tomcat-servlet-api:8.0.26'


apply(plugin: 'idea')
apply(plugin: 'cuba')

cuba {
    artifact {
        group = 'com.company.cubasampleboard'
        version = '0.1'
        isSnapshot = true
    }
    tomcat {
        dir = "$project.rootDir/deploy/tomcat"
    }
}

def hsql = 'org.hsqldb:hsqldb:2.2.9'

configure([globalModule, coreModule, guiModule, webModule]) {
    apply(plugin: 'java')
    apply(plugin: 'maven')
    apply(plugin: 'idea')
    apply(plugin: 'cuba')

    dependencies {
        testCompile('junit:junit:4.12')
    }

    task sourceJar(type: Jar) {
        from file('src')
        classifier = 'sources'
    }

    artifacts {
        archives sourceJar
    }
}

configure(globalModule) {
    task enhance(type: CubaEnhancing)
    
    
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        provided(servletApi)
        jdbc(hsql)
        testRuntime(hsql)

    }

    task cleanConf(description: 'Cleans up conf directory') << {
        def dir = new File(cuba.tomcat.dir, '/conf/board-core')
        if (dir.isDirectory()) {
            ant.delete(includeemptydirs: true) {
                fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
            }
        }
    }

    task deploy(dependsOn: &#91;assemble, cleanConf&#93;, type: CubaDeployment) {
        appName = 'board-core'
        appJars('board-global', 'board-core')
    }

    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'hsql'
        host = 'localhost'
        dbName = 'cubasampleboard'
        dbUser = 'sa'
        dbPassword = ''
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'hsql'
        host = 'localhost'
        dbName = 'cubasampleboard'
        dbUser = 'sa'
        dbPassword = ''
    }
}

configure(guiModule) {
    dependencies {
        compile(globalModule)

    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/company/cubasampleboard/**"
        into "$cuba.tomcat.dir/conf/board"
    }
}

configure(webModule) {
    configurations {
        webcontent
    }

    dependencies {
        provided(servletApi)
        compile(guiModule)

    }
    
    task webArchive(type: Zip) {
        from file("$buildDir/web")
        from file('web')
        classifier = 'web'
    }

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/company/cubasampleboard/**"
        into "$cuba.tomcat.dir/conf/board"
    }

    task clearMessagesCache(type: CubaClearMessagesCache) {
        appName = 'board'
    }
    deployConf.dependsOn clearMessagesCache

    task cleanConf(description: 'Cleans up conf directory') << {
        def dir = new File(cuba.tomcat.dir, '/conf/board')
        if (dir.isDirectory()) {
            ant.delete(includeemptydirs: true) {
                fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
            }
        }
    }

    task deploy(dependsOn: &#91;assemble, cleanConf&#93;, type: CubaDeployment) {
        appName = 'board'
        appJars('board-global', 'board-gui', 'board-web')
    }
}

task undeploy(type: Delete, dependsOn: ':board-web:cleanConf') {
    delete("$cuba.tomcat.dir/shared")
    delete("$cuba.tomcat.dir/webapps/board-core")
    delete("$cuba.tomcat.dir/webapps/board")
}

task restart(dependsOn: &#91;'stop', ':board-core:deploy', ':board-web:deploy'&#93;, description: 'Redeploys applications and restarts local Tomcat') << {
    ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
        not {
            socket(server: 'localhost', port: '8787')
        }
    }
    start.execute()
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.4'
}

apply from: 'extra.gradle'

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

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'gradle-release'
            username = "${artifactory_user}"
            password = "${artifactory_password}"

        }       
        defaults {
            publications ('mavenJava')
            publishArtifacts = true
        }
    }
}

gradle.properties:

artifactory_user=user
artifactory_password=password
artifactory_contextUrl=http://192.168.*.*:8081/artifactory

build_gradle.zip (1.9K)

1 Like

Hello Ivan,

thank you very much, my missing puzzle was the publishing task.

Your approach help us to upload the artifacts. What is the difference to the task install, except the target?

One more question about downloading (=resolving) the dependencies.

Currently we have configured as bellow:


artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
    }
    resolve {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
    }
}

But without following section in buildscript gradle is not able to resolve our internal dependencies (we built certain sub modules).


        maven {
            url "https://repo-path/gradle-dev-local"
            credentials {
                username(rootProject.hasProperty('artifactory_user') ? rootProject['artifactory_user'] : System.getenv('ARTIFACTORY_USER'))
                password(rootProject.hasProperty('artifactory_password') ? rootProject['artifactory_password'] : System.getenv('ARTIFACTORY_PASSWORD'))
            }
        }

Did you may know the reason for?

1 Like

My expectation was that for each module (core, global, web ect.) artifacts will be published but this not the case.

I found a workaround by using task ‘upload’ and following gradle.properties:


uploadUrl=https://repo-path/gradle-dev-local
uploadUser=user
uploadPassword=password

The workaround does not help us because the build.info is missing then.

I am not sure, but check the string please:

url "[url=https://repo-path/gradle-dev-local"]https://repo-path/gradle-dev-local"[/url];

Is it resolved in the browser?
In my case I use the following line:

url "[url=http://192.168.0.1:8081/artifactory/gradle-release-local/"]http://192.168.0.1:8081/artifactory/gradle-release-local/"[/url];

Thanks but this was just an example to describe the situation in general, our Repository runs as SASS on jfrog site and I want to hide the real URL.
Let me summarize: the publish workaround by uploadArchives is working but we want that the regular publish (=artifacoryPublish) will bring all artifacts (jar, srcjar, javadoc, pom etc) into the repository at once.
So far I understand the cuba gradle plugin it takes the repsonsibility for it, because it’s populate the properties on all projects (because of the multi module/project script). The missing part is the publishing section in each project. gradle userguide for publishing
Therefor I was asking for install task because this task works for publishing artifacts to the local repository. So it must be possible to use it to implement a proper publish to an remote repository like artifactory.

Hi,

Finally, we have found and checked real-life configuration of Artifactory Gradle plugin:


// buildscript

buildscript {
    // ...
    dependencies {
        // ...
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1" 
        // there is a bug in the latest.release with app-global publish, use 4.0.1
    }
}

// after all the content in build.gradle

allprojects {
    apply plugin: "com.jfrog.artifactory"
}
artifactoryPublish.skip = true

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }
        defaults {
            publishConfigs('archives') // we always use archives

            publishArtifacts = true
            publishBuildInfo = true
            publishPom = true
            publishIvy = false
        }
    }
}

Create gradle.properies file:


artifactory_user=admin
artifactory_password=password
artifactory_contextUrl=http://artifactory-host/artifactory

Build your project and run publishing using:


> gradle assemble artifactoryPublish

You will see the following output:


Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-core/0.1-SNAPSHOT/app-core-0.1-SNAPSHOT-sources.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-core/0.1-SNAPSHOT/app-core-0.1-SNAPSHOT.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-core/0.1-SNAPSHOT/app-core-0.1-SNAPSHOT.pom
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-global/0.1-SNAPSHOT/app-global-0.1-SNAPSHOT-sources.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-global/0.1-SNAPSHOT/app-global-0.1-SNAPSHOT.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-global/0.1-SNAPSHOT/app-global-0.1-SNAPSHOT.pom
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-gui/0.1-SNAPSHOT/app-gui-0.1-SNAPSHOT-sources.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-gui/0.1-SNAPSHOT/app-gui-0.1-SNAPSHOT.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-gui/0.1-SNAPSHOT/app-gui-0.1-SNAPSHOT.pom
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-web/0.1-SNAPSHOT/app-web-0.1-SNAPSHOT-sources.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-web/0.1-SNAPSHOT/app-web-0.1-SNAPSHOT-web.zip
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-web/0.1-SNAPSHOT/app-web-0.1-SNAPSHOT.jar
Deploying artifact: http://artifactory-host/artifactory/gradle-dev-local/com/company/appdemo/app-web/0.1-SNAPSHOT/app-web-0.1-SNAPSHOT.pom
Deploying build descriptor to: http://artifactory-host/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://artifactory-host/artifactory/webapp/builds/app-demo/1500910160433

I hope it will be useful for your project. To resolve artifacts from your repository you should add artifactory as a maven repository to buildscript gradle section as you shown above.

1 Like

Hello Yuriy,
excellent job! Thank you very much!!
Now the artifact publication works.
This issue can be closed now.