I am new to gradle and artifactory both.
What I want to accomplish is to have separate projects with each project creating a jar file that will be used by other projects in the same application.
For example, I have a utility project that has, wait for it..., utility classes. I then have a services project with the, that's right, services. The services use the utilities to accomplish some of their work.
I've spent several hours and finally have the utility project committing to my artifactory repository using this script:
buildscript {
repositories {
mavenLocal()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
apply plugin: 'java'
apply plugin: "com.jfrog.artifactory"
archivesBaseName = 'heavyweight-software-util'
repositories {
mavenCentral()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
}
dependencies {
testCompile("junit:junit:4.11")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
artifactory {
contextUrl = "http://picard:8080/artifactory" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
username = 'xxxx'
password = "xxxx"
maven = false
ivy {
ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
mavenCompatible = false
}
}
}
resolve {
repository {
repoKey = 'libs-release'
username = 'xxxx'
password = "xxxx"
maven = false
ivy {
ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
mavenCompatible = false
}
}
}
}
When I run this I get the following:
C:\Users\thom\git\utility\Utility>gradle artifactoryPublish
[buildinfo] Not using buildInfo properties file for this build.
:artifactoryPublish
Deploying build descriptor to: http://picard:8080/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://picard:8080/a
rtifactory/webapp/builds/Utility/1436807848026/2015-07-13T13:17:27.704-0400/
BUILD SUCCESSFUL
Total time: 6.874 secs
Hurrah! Or, so I thought.
Because as soon as this wrapped up, I thought, "Now how do I get this file out." I looked at the links above and they're there, but I can't see how this is a jar file. I tried looking at libs-release-local in my tree browser, but it shows 0 artifacts.
Here's what I found under build info JSON under the build:
{
"version" : "1.0.1",
"name" : "Utility",
"number" : "1436807848026",
"type" : "GRADLE",
"buildAgent" : {
"name" : "Gradle",
"version" : "2.4"
},
"agent" : {
"name" : "Gradle",
"version" : "2.4"
},
"started" : "2015-07-13T13:17:27.704-0400",
"durationMillis" : 474,
"principal" : "thom",
"artifactoryPrincipal" : "admin",
"licenseControl" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoDiscover" : false,
"licenseViolationsRecipientsList" : "",
"scopesList" : ""
},
"buildRetention" : {
"count" : -1,
"deleteBuildArtifacts" : true,
"buildNumbersNotToBeDiscarded" : [ ]
},
"governance" : {
"blackDuckProperties" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoCreateMissingComponentRequests" : false,
"autoDiscardStaleComponentRequests" : false
}
}
}
I've googled and researched and can't seem to figure out how to make use of the jar file I have committed to my repository.
OK, after reading: https://docs.gradle.org/current/userguide/publishing_ivy.html and https://docs.gradle.org/current/userguide/artifact_management.html and finally, http://forums.jfrog.org/405-HTTP-method-PUT-not-supported-td5786632.html I have pieced together an answer to my question. I have attached the build script that performs the upload properly...
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
apply plugin: 'java'
apply plugin: 'ivy-publish'
archivesBaseName = 'heavyweight-software-util'
repositories {
mavenCentral()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
testCompile("junit:junit:4.11")
}
publishing {
publications {
ivy(IvyPublication) {
organisation 'com.heavyweightsoftware'
module 'heavyweight-util'
revision '1.0'
from components.java
}
}
repositories {
ivy {
url 'http://picard:8080/artifactory/libs-release-local'
credentials {
username "xxxxx"
password "xxxxx"
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
Now that I know that the publication is working correctly, I should be able to use the repository without issue.
Related
I am following instructions in the Sonatype documentation for publishing a gradle project.
I have the following gradle version.
$ ./gradlew --version
------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------
Build time: 2022-11-25 13:35:10 UTC
Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Mac OS X 10.16 x86_64
When I try to use the uploadArchives task as given in their example, I get the following error:
$ ./gradlew uploadArchives
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/ferozed/stash/libs/mask-json-field-transform/build.gradle' line: 167
* What went wrong:
A problem occurred evaluating root project 'mask-json-field-transform'.
> Could not find method uploadArchives() for arguments [build_6yphclnk6m8p3rtmq5h7m56li$_run_closure12#19fbeecd] on root project 'mask-json-field-transform' of type org.gradle.api.Project.
This is my build.gradle file
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
}
}
plugins {
id 'java' // so that we can use 'implementation', 'testImplementation' for dependencies
id 'maven-publish'
id 'signing'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
jcenter()
mavenCentral()
maven {
url = "https://packages.confluent.io/maven"
}
maven {
url = "https://jitpack.io"
}
}
group = 'io.github.ferozed.kafka.connect'
version = '0.1'
dependencies {
// Kafka
implementation group: 'org.apache.kafka', name: 'connect-api', version: '3.3.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.1'
implementation 'com.github.jcustenborder.kafka.connect:connect-utils:0.7.173'
implementation 'com.github.jcustenborder.kafka.connect:kafka-connect-transform-common:0.1.0.14'
//test
testImplementation(platform('org.junit:junit-bom:5.9.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("io.mockk:mockk:1.9.2")
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/avro", "src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
plugins.withId("com.github.johnrengelman.shadow"){
//this block requires the java plugin to be applied first.
plugins.withId("java"){
shadowJar {
//We are overriding the default jar to be the shadow jar
classifier = null
exclude 'META-INF'
exclude 'META-INF/*.INF'
exclude 'META-INF/license/*'
}
jar {
manifest {
attributes(
'Built-By' : System.properties['user.name'],
'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
}
tasks.build.dependsOn tasks.shadowJar
tasks.shadowJar.mustRunAfter tasks.jar
tasks.shadowJar.mustRunAfter tasks.javadocJar
tasks.shadowJar.mustRunAfter tasks.sourcesJar
}
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = 'Mask Json Field Transform'
description = 'A kafka connect transform to remove the value of a sensitive field in a json document.'
url = 'https://github.com/ferozed/mask-json-field-transform'
properties = [
myProp: "value",
"prop.with.dots": "anotherValue"
]
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'ferozes'
name = 'Feroze Daud'
email = 'ferozed.oss#gmail.com'
}
}
scm {
connection = 'scm:git:git#github.com:ferozed/mask-json-field-transform.git'
developerConnection = 'scm:git:git#github.com:ferozed/mask-json-field-transform.git'
url = 'https://github.com/ferozed/mask-json-field-transform'
}
}
}
}
}
signing {
sign configurations.archives
sign publishing.publications.mavenJava
}
tasks.signArchives.dependsOn tasks.shadowJar
artifacts {
archives javadocJar, sourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { deployment -> signing.signPom(deployment) }
repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Example Application'
packaging 'jar'
// optionally artifactId can be defined here
description 'A kafka connect transform to remove the value of a sensitive field in a json document.'
url 'https://github.com/ferozed/mask-json-field-transform'
scm {
connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
url 'https://github.com/ferozed/mask-json-field-transform'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'ferozed'
name 'Feroze Daud'
email 'feroz#gmail.com'
}
}
}
}
}
}
What am I doing wrong?
First and foremost, you may not need to 'fix the error' so to speak, in that it appears the problematic code MAY be able to be outright deleted. However...
To fix the error...
Could not find method uploadArchives() for arguments [build_6yphclnk6m8p3rtmq5h7m56li$_run_closure12#19fbeecd] on root project 'mask-json-field-transform' of type org.gradle.api.Project.
This is telling us that uploadArchives is not valid. See immediately below.
I believe you may need to use the maven plugin to access this functionality.
https://github.com/siddeshbg/gradle-uploadArchives/blob/master/README.md
to do this, add:
id 'maven'
to your plugins{}
block.
The above example explains that the maven plugin is responsible for doing this
The Maven plugin adds support for deploying artifacts to Maven repositories
It is worth considering also that the author of the above repository claims:
This is the legacy publishing mechanism, should not be used in newer
builds
Now... on to the better solution, forgetting the maven plugin, in favor of the maven-publish plugin you're already using...
I do not personally work with Maven often enough to know what other mechanisms one should use, but Google suggests that perhaps the maven-publish plugin you're using might do this WITHOUT the 'uploadArchives{}' portion of your code that is causing the error.
See:
https://docs.gradle.org/current/userguide/publishing_maven.html
Per this page, it would seem the entire uploadArchives block is unnecessary
I'm publishing an SDK composed of different modules to Artifactory, using gradle's publications and the Artifactory plugin.
Everything is published and the modules are all grouped in a build with the name and the version that I have specified in the gradle.property file:
buildInfo.build.name=test.buildname
buildInfo.build.number=0.1.3
The problem is that the modules are all published with the default name = module name and with not version and no dependencies at least what Artifactory shows me for the moduleid;number of artifacts; dependencies is something like this:
my-real-project-name:FullModuleName:unspecified; 2; 0
Here a snippet of the grade file for publishing (it is applied to each the build.gradle scripts for all the module:
apply from: "../../versioning.gradle"
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
publishing {
publications {
modulePublications(MavenPublication) {
artifact("$buildDir/outputs/aar/$archivesBaseName-release.aar")
groupId 'com.mygroup'
version '0.1.2'
artifactId shortName
println "shortName=$shortName"
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
println "dependency=$it"
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publications('modulePublications')
properties = ['dev.team': 'android-sdk']
publishArtifacts = true
publishPom = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
In the project level build.gradle file I have:
buildscript {
repositories {
google()
jcenter()
maven {
url 'http://localhost:8081/artifactory/gradle-dev'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2"
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
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
}
}
}
After I publish I see a build-info.json file created in the build folder:
{
"version" : "1.0.1",
"name" : "test.buildname",
"number" : "0.1.3",
"type" : "GRADLE",
"buildAgent" : {
"name" : "Gradle",
"version" : "6.4"
},
"agent" : {
"name" : "Gradle",
"version" : "6.4"
},
"started" : "2020-05-22T11:25:55.441+0100",
"durationMillis" : 1365,
"principal" : "my username on my machine",
"artifactoryPrincipal" : "the user name I set for artifactory in the gradle.property file",
"artifactoryPluginVersion" : "Unknown",
"vcs" : [ ],
"licenseControl" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoDiscover" : false,
"scopesList" : "",
"licenseViolationsRecipientsList" : ""
},
"modules" : [ {
"id" : "projectname-android-sdk.sdk:ModuleName1:unspecified",
"artifacts" : [ {
"type" : "aar",
"sha1" : "6cf10ee05254c14cc74e021a150f939cf0b9f55c",
"md5" : "3007163c98733e72ef103ede05275a2f",
"name" : "ModuleName1-0.0.1.aar"
}, {
"type" : "pom",
"sha1" : "850ab02427a7f23680679ebbf05ca3b809809700",
"md5" : "5952e9f0e90df9543f6fd8ede6168b91",
"name" : "ModuleName1-0.0.1.pom"
} ],
"excludedArtifacts" : [ ],
"dependencies" : [ ]
}, {
"id" : "projectname-android-sdk.sdk:ModuleName2:unspecified",
"artifacts" : [ {
"type" : "aar",
"sha1" : "c246f3c188ebb064c4a87066863f55eae5553b4e",
"md5" : "0b8c516d3a3907c9c764046e718a6796",
"name" : "ModuleName2-0.0.1.aar"
}, {
"type" : "pom",
"sha1" : "4efacb8ddbe214b8b95804c0b4b0fa195eb2758d",
"md5" : "773da347a05bfacac2176b3f26010812",
"name" : "ModuleName2-0.0.1.pom"
} ],
"excludedArtifacts" : [ ],
"dependencies" : [ ]
} ],
"governance" : {
"blackDuckProperties" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoCreateMissingComponentRequests" : false,
"autoDiscardStaleComponentRequests" : false
}
}
}
Please notice the "id" : "projectname-android-sdk.sdk:ModuleName1:unspecified" that is what I see on Artifactory.
projectname-android-sdk is the name of the project, .sdk comes from the fact that each module is in a subfolder, of the project's root folder, called sdk. ModuleName1 is the name of one of the modules.
I have partially fixed the issue: I was not clearing the build before calling Artifactory and I was pushing old builds. I thought that I was labelling the aar and that it wasn't important to build them again.
Now I'm calling:
./gradlew clean assembleDebug
./gradlew artifactoryPublish
Now that I'm building again, I get a new build-info.json with the things I was expecting.
I have also googled what a Build is on Artifactory and I found this. I can summarise saying that I had confused the info about the build with the info about the published artifacts.
When I call ./gradlew artifactoryPublish at the end I see:
[pool-79-thread-1] Deploying artifact:
https://justatest4artifactory.jfrog.io/artifactory/gradle-dev-local/com/mygroup/ModuleName1/0.1.3/Nickname1-0.1.2.aar
where 0.1.3 is the buildInfo.build.number and 0.1.2 is the version of the artifact.
I'm trying to use 2 different plugins that have the same root block name, what's causing conflict and error in the build process.
The 2 plugins are defined in the build.gradle :
plugins {
id 'java'
id 'application'
id 'com.benjaminsproule.swagger' version '1.0.8'
id 'org.detoeuf.swagger-codegen' version '1.7.4'
}
apply plugin: 'org.detoeuf.swagger-codegen'
version '1.0-SNAPSHOT'
mainClassName = 'ServiceMain'
swagger {
apiSource {
springmvc = true
locations = ['com.google.charger']
schemes = ['https']
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
}
swaggerDirectory = 'swagger'
swaggerFileName = 'charger-service-api-swagger'
attachSwaggerArtifact = true
}
}
swagger {
inputSpec = "${project.projectDir}/swagger/charger-service-api-swagger.json"
outputDir = file("${project.projectDir}/../charger-server-api-client/")
lang = 'java'
additionalProperties = [
'invokerPackage' : 'com.google.ev.charger.server',
'modelPackage' : 'com.google.ev.charger.server.model',
'apiPackage' : 'com.google.ev.charger.server.api',
'dateLibrary' : 'joda',
'groupId' : 'com.google.ev',
'artifactId' : 'charger.server',
'artifactVersion' : '1.0.0',
'hideGenerationTimestamp': 'true'
]
}
sourceSets {
swagger {
java {
srcDir file("${project.buildDir.path}/swagger/src/main/java")
}
}
}
As you can see both plugins starts with the same block name (swagger),
Is there any way to specify the plugin for each configuration?
I ended up using code to resolve this issue,
I am using a property called "CreateSwagger" that I'm passing (either from CLI or from gradle.properties file) to separate the 2 scenarios.
The issue I had is that the plugins {} block is not allowed inside the if that evaluates the condition so I needed to use the "old" legacy plugin " apply plugin:"
This is how my build.gradle ended up looking:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.benjaminsproule:swagger-gradle-plugin:1.0.8"
classpath "gradle.plugin.org.detoeuf:swagger-codegen-plugin:1.7.4"
}
}
plugins {
id 'java'
id 'application'
id 'maven'
}
if(project.properties.containsKey('CreateSwagger')){
apply plugin: "com.benjaminsproule.swagger"
} else {
apply plugin: 'org.detoeuf.swagger-codegen'
}
version '1.0-SNAPSHOT'
mainClassName = 'EVChargerRestServiceMain'
if(project.properties.containsKey('CreateSwagger')){
swagger {
apiSource {
springmvc = true
locations = ['com.google.charger']
schemes = ['https']
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
}
swaggerDirectory = 'swagger'
swaggerFileName = 'charger-service-api-swagger'
attachSwaggerArtifact = true
}
}
}
else {
swagger {
inputSpec = "${project.projectDir}/swagger/charger-service-api-swagger.json"
outputDir = file("${project.projectDir}/../charger-server-api-client/")
lang = 'java'
additionalProperties = [
'invokerPackage' : 'com.google.ev.charger.server',
'modelPackage' : 'com.google.ev.charger.server.model',
'apiPackage' : 'com.google.ev.charger.server.api',
'dateLibrary' : 'joda',
'groupId' : 'com.google.ev',
'artifactId' : 'charger.server',
'artifactVersion' : '1.0.0',
'hideGenerationTimestamp': 'true'
]
}
}
I have a git submodule (of which I have no control of) in my project which contains file named publish.gradle. The contents of this file are:
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
version = System.getenv()['VERSION'] ?: version
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = repoBaseUrl
publish {
String publishRepoKey = version.endsWith('SNAPSHOT') ? repoKeySnapshot : repoKeyRelease
repository {
repoKey = publishRepoKey // The Artifactory repository key to publish to
username = System.getenv()['ARTIFACTORY_USERNAME'] ?: artifactoryUser // The publisher user name
password = System.getenv()['ARTIFACTORY_PASSWORD'] ?: artifactoryPassword // The publisher password
}
defaults {
publications('mavenJava')
publishArtifacts = true
publishPom = true
}
}
resolve {
repoKey = repoKey
}
}
In my build.gradle file I have the following line:
apply from: "${rootDir}/submodule/gradle/publish.gradle"
When I try to add the following line after this line:
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing.publications.mavenJava.artifact sourceJar {
classifier 'sources'
}
Then the correct things get published, except that the pom file in the repository only contains a <dependencyManagement/> section and all the dependencies are missing. When I remove the above lines from build.gradle the pom is correct.
Try to override the all publishing block with :
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
Here is my 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'
}
}
Based on this current setup:
To build my JAR I have to run gradle clean build groovydoc sourcesJar dist and then
To publish to Artifactory, I have to run a second command of gradle artifactoryPublish
Two things I'm looking to change here:
gradle artifactoryPublish only publishes my built JAR and a dynamically-created POM to Artifactory. I'd like it to also publish the sources JAR that my build is creating. How?; and
Ideally I'd like to be able to do all of the above by just invoking gradle publish instead of having to run the 2 commands sequentially. Is this possible? If so, how?
When it comes to publishing source you need to modify your script in the following way:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact (sourcesJar) {
classifier = 'sources'
}
}
}
}
When it comes to a single command what you need to do is to define dependencies between tasks. Unfortunately I can't try the script so it may be redundant but should do the job:
artifactoryPublish.dependsOn('clean', 'build', 'groovydoc', 'sourcesJar', 'dist')
publish.dependsOn(artifactoryPublish)