Have a question? Want to report an issue? Contact JFrog support

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We highly recommend also using our

Newtablink
Textexamples
URLhttps://github.com/JFrogDev/project-examples/tree/master/gradle-examples
 as a reference when configuring the DSL in your build scripts.

 

Tip

Mandatory items within the relevant context are prefixed with '+'. All other items are optional.

Code Block
artifactory {
  +contextUrl = 'http://repo.myorg.com/artifactory'   //The base Artifactory URL if not overridden by the publisher/resolver
  publish {
    contextUrl = 'http://repo.myorg.com/artifactory'   //The base Artifactory URL for the publisher
    //A closure defining publishing information
    repository {
      +repoKey = 'integration-libs'   //The Artifactory repository key to publish to
      +username = 'deployer'          //The publisher user name
      password = 'deployerPaS*'       //The publisher password
      ivy {
        //Optional section for configuring Ivy publication. Assumes Maven repo layout if not specified
        ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
        artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
        mavenCompatible = true //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified
      }
    }
    defaults {
		//List of Gradle Publications (names or objects) from which to collect the list of artifacts to be deployed to Artifactory.
        publications ('ivyJava','mavenJava','foo')
		////List of Gradle Configurations (names or objects) from which to collect the list of artifacts to be deployed to Artifactory. 
		publishConfigs('archives', 'published')                    
        properties = ['qa.level': 'basic', 'q.os': 'win32, deb, osx']  //Optional map of properties to attach to all published artifacts
        /*
        The properties closure in the "defaults" task uses the following syntax:
        properties {
            publicationName 'group:module:version:classifier@type', key1:'value1', key2:'value2', ...
        }
        publicationName: A valid name for a publication of the project. You can use all to apply the properties to all publications.
        group:module:version:classifier@type: A filter that specifies the artifacts to which properties should be attached. 
		The filter may contain wildcards: * for all characters or ? for a single character.
        key:'value': A list of key/value properties that will be attached to to the published artifacts matching the filter.  
        */
        properties {                                                   //Optional closure to attach properties to artifacts based on a list of artifact patterns per project publication
            foo '*:*:*:*@*', platform: 'linux', 'win64'                //The property platform=linux,win64 will be set on all artifacts in foo publication
            mavenJava 'org.jfrog:*:*:*@*', key1: 'val1'                //The property key1=val1 will be set on all artifacts part of the mavenJava publication and with group org.jfrog
            all 'org.jfrog:shared:1.?:*@*', key2: 'val2', key3: 'val3' //The properties key2 and key3 will be set on all published artifacts (all publications) with group:artifact:version 
																	   //equal to org.jfrog:shared:1.?
        }
        publishBuildInfo = true   //Publish build-info to Artifactory (true by default)
        publishArtifacts = true   //Publish artifacts to Artifactory (true by default)
        publishPom = true   //Publish generated POM files to Artifactory (true by default).
        publishIvy = true   //Publish generated Ivy descriptor files to Artifactory (true by default).
    }
  }
  resolve {
    contextUrl = 'http://repo.myorg.com/artifactory'   //The base Artifactory URL for the resolver
    repository {
      +repoKey = 'libs-releases'  //The Artifactory (preferably virtual) repository key to resolve from
      username = 'resolver'       //Optional resolver user name (leave out to use anonymous resolution)
      password = 'resolverPaS*'   //The resolver password
      maven = true                //Resolve Maven-style artifacts and descriptors (true by default)
      ivy {
        //Optional section for configuring Ivy-style resolution. Assumes Maven repo layout if If not specified
        ivyLayout = ...
        artifactLayout = ...
        mavenCompatible = ...
      }
    }
  }
  // Redefine basic properties of the build info object
  clientConfig.setIncludeEnvVars(true)
  clientConfig.setEnvVarsExcludePatterns('*password*,*secret*')
  clientConfig.setEnvVarsIncludePatterns('*not-secret*')
  clientConfig.info.addEnvironmentProperty('test.adding.dynVar',new java.util.Date().toString())
  clientConfig.info.setBuildName('new-strange-name')
  clientConfig.info.setBuildNumber('' + new java.util.Random(System.currentTimeMillis()).nextInt(20000))
  clientConfig.timeout = 600 // Artifactory connection timeout (in seconds). The default timeout is 300 seconds.
}

Tip
titleControlling how environment variables are exposed

As shown in the example above, you can control which environment variables are exposed in clientConfig.setIncludeEnvVars using clientConfig.setEnvVarsExcludePatterns and clientConfig.setEnvVarsIncludePatterns. These calls specify which environment variables should be excluded or included respectively using a parameter which is a comma-separated list of expressions to exclude or include. The expressions can use a star ('*') wildcard to specify multiple environment variables.

Code Block
languagejava
titleUsing the old Gradle publishing mechanism?
collapsetrue
If you are using the old Gradle publishing mechanism, you need to replace the above defaults closure with the following one:
 
defaults {
        //This closure defines defaults for all 'artifactoryPublish' tasks of all projects the plugin is applied to
        publishConfigs ('a','b','foo')                                 //Optional list of configurations (names or objects) to publish.
                                                                       //The 'archives' configuration is used if it exists and no configuration is specified
        mavenDescriptor = '/home/froggy/projects/proj-a/fly-1.0.pom'   //Optional alternative path for a POM to be published (can be relative to project baseDir)
        ivyDescriptor = 'fly-1.0-ivy.xml'                              //Optional alternative path for an ivy file to be published (can be relative to project baseDir)
        properties = ['qa.level': 'basic', 'q.os': 'win32, deb, osx']  //Optional map of properties to attach to all published artifacts
        /*
        The properties closure in the "defaults" task uses the following syntax:
        properties {
            configuration 'group:module:version:classifier@type', key1:'value1', key2:'value2', ...
        }
        configuration: A configuration that is a valid name of a configuration of the project. You can use all to apply the properties to all configurations.
        group:module:version:classifier@type: An artifact specification filter for matching the artifacts to which properties should be attached. 
		The filter may contain wildcards: * for all characters or ? for a single character.
        key:'value': A list of key/value(s) properties that are attached to to the published artifacts matching the filter.
        */
        properties {                                                   //Optional closure to attach properties to artifacts based on a list of artifact patterns per project configuration
            foo '*:*:*:*@*', platform: 'linux', 'win64'                //The property platform=linux,win64 will be set on all artifacts in foo configuration
            archives 'org.jfrog:*:*:*@*', key1: 'val1'                 //The property key1=val1 will be set on all artifacts part of the archives configuration and with group org.jfrog
            all 'org.jfrog:shared:1.?:*@*', key2: 'val2', key3: 'val3' //The properties key2 and key3 will be set on all published artifacts (all configurations) with group:artifact:version 
                                                                       //equal to org.jfrog:shared:1.?
        }
        publishBuildInfo = true   //Publish build-info to Artifactory (true by default)
        publishArtifacts = true   //Publish artifacts to Artifactory (true by default)
        publishPom = true         //Publish generated POM files to Artifactory (true by default)
        publishIvy = false        //Publish generated Ivy descriptor files to Artifactory (false by default)
    }

...