Home > Enterprise >  How to publish to Artifactory with Gradle without publishing dependent projects
How to publish to Artifactory with Gradle without publishing dependent projects

Time:02-19

I'm updating some build.gradle files to add Artifactory publishing. In some cases I want to publish the top level project's artifacts without publishing artifacts for its dependent projects. The dependent projects get published on their own or when built by a different project.

I've added basic publishing and artifactory tasks to the build.gradle files and they work, but for example if there's a project called "api" that has a dependent project called "db", when I run the build.gradle for "api", it publishes the artifacts for both "api" and "db". I want it to only publish the api artifacts.

I'm not having much luck finding what I want on Jfrog's site. The documentation mentions "Use the artifactoryPublish.skip flag to deactivate analysis and publication", but honestly I don't know what to do with that and if it would help in my case.

The gradle scripts are referencing dependencies like this:

implementation project(path: ':db', configuration: 'default')

I've run the builds in both Eclipse and Jenkins. We use Gradle 7.4. I'm calling the clean, build, and artifactoryPublish tasks. I suspect there's probably an easy way to do this, and I'm just not seeing it.

For reference, this is my publishing task:

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

And here's the publish part of the artifactory section:

publish {
    repository {
        repoKey = 'libs-release-local'
        username = "${artifactory_user}"
        password = "${artifactory_password}"
        ivy {
          ivyLayout = '[organization]/[module]/[revision]/ivy-[revision].xml'
          artifactLayout = '[organization]/[module]/[revision]/[artifact]-[revision].[ext]'
          mavenCompatible = true 
        }
    }
    defaults {
        publications('mavenJava')
        publishArtifacts = true
        properties = ['qa.level': 'basic', 'dev.team' : 'core']
        publishPom = true
        publishIvy = true
    }
}

CodePudding user response:

I found an answer. For a project that has "db" as a dependency, after the dependencies section of my build.gradle file, I added the following:

gradle.startParameter.excludedTaskNames  = "db:artifactoryPublish"

Now when I run the artifactoryPublish task for the api project, it does not execute for the db project, too.

CodePudding user response:

For excluding the "db" project from publishing to Artifactory, you can add the following in your build.gradle file:

project('db') {
    artifactoryPublish.skip = true
}
  • Related