Reputation: 1137
I have a build.gradle like this
/**
* Gradle plugins.
*/
plugins {
id "org.sonarqube" version "3.0"
id "com.avast.gradle.docker-compose" version "0.13.0"
id "jacoco"
}
/**
* import extensions for dependencies.
*/
apply from: 'dependencies.gradle'
/**
* Root project variables.
*/
ext {
localDevelopment = System.env.ENVIRONMENT != null ? System.env.ENVIRONMENT == 'LOCAL' : false
javaInfo = "${System.properties['java.version']}"
buildNumber = System.properties['buildNumber'] != null ? "${System.properties['buildNumber']}" : LocalDateTime.now()
}
/**
* Apply to all projects (includes root).
*/
allprojects {
apply plugin: 'maven-publish'
apply plugin: 'java-library'
group = 'com.gradle.test'
version = 'test-21.14.7.pipeline.version'
description = 'Test application'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenLocal()
maven { url 'https://artifactory2.company.co.nz/company-maven' }
maven { url 'https://artifactory2.company.co.nz/company-maven-plugin' }
maven { url 'https://repo.maven.apache.org/maven2' }
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
/**
* Apply manifest entries for all jars.
*/
jar {
manifest {
attributes (
"Created-By": "Gradle ${gradle.gradleVersion}",
"Built-By": System.properties['user.name'],
"Build-Jdk": javaInfo,
"Implementation-Title": project.name,
"Implementation-Version": rootProject.version,
"Implementation-Vendor-Id": rootProject.group,
"Implementation-Vendor": rootProject.ext.vendor,
"Specification-Version": rootProject.version,
)
}
}
/**
* Fail the build if a library has a version conflict. Substitute with version defined in 'forcedLibs'.
*/
configurations {
all {
resolutionStrategy {
failOnVersionConflict()
force forcedLibs
}
}
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
}
/**
* Apply to sub-projects (excludes root).
*/
subprojects {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
/**
* Custom task to build dependency report for all sub-projects from root.
*/
task allDeps(type: DependencyReportTask) {}
/**
* Custom task to build dependency insight report for all sub-projects from root.
*/
task allDepInsight(type: DependencyInsightReportTask) {}
}
/**
* Docker Compose plugin settings.
*/
dockerCompose {
useComposeFiles = ["${ rootProject.buildDir }/docker-compose.yml"]
projectName = rootProject.name
}
/**
* Copy Docker files from ./docker to Docker run directory.
*/
task copyDocker(type: Copy) {
from "${ rootProject.projectDir }/docker"
into dir.dockerRunDir
}
/**
* Link 'copyDocker' as dependent on 'copyEar'.
*/
copyDocker.dependsOn ':test-ear:copyEar'
/**
* Link 'composeUp' as dependent on 'copyDocker'.
*/
composeUp.dependsOn copyDocker
/**
* Sonarqube plugin settings.
*/
sonarqube {
properties {
property "sonar.host.url", "http://sonarqube.company.co.nz:9000"
property "sonar.coverage.exclusions", "com/ibm/**/*, **/*.hbm.xml, **/*.sql, " +
"**/*.IFD, **/*.mfd, **/*.xpr, **/*.cob, **/com/company/nzlo/messaging/**/*, " +
"**/com/company/nzlo/si/**/*, **/*.JPG, **/*.jpg, **/*.ifd, **/*.bmp, **/*.mdf, **/*.xml"
property "sonar.test.exclusions", "**/test/*"
property "sonar.scm.disabled", "true"
property "sonar.dynamicAnalysis", "reuseReports"
}
}
/**
* Task to configure jacoco and gather code coverage from subprojects. This is applied conditionally
* as not all subprojects will use the jacoco plugin ('test-ear').
* Reference: [Gradle example](https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html)
*/
task codeCoverageReport(type: JacocoReport) {
dependsOn(subprojects.test)
/**
* Configure source sets and execution data for sub project's tests.
*/
subprojects { s ->
s.plugins.withType(JacocoPlugin).configureEach {
s.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) })
.configureEach { testTask ->
sourceSets s.sourceSets.main
executionData(testTask)
}
}
/**
* Configure plugin for subprojects.
*/
s.tasks.withType(JacocoPluginExtension).configureEach {
toolVersion = "0.8.5"
reportsDir = file("${buildDir}/reports")
}
}
reports {
xml.enabled true
html.enabled true
}
}
/**
* Link 'sonarqube' as dependent on 'codeCoverageReport'.
*/
tasks['sonarqube'].dependsOn codeCoverageReport
/**
* Defines wrapper version and distribution url.
*/
wrapper {
gradleVersion = '6.5'
distributionUrl "https://artifactory2.company.co.nz/gradle-dist-remote-cache/gradle-${gradleVersion}-bin.zip"
}
Running ./gradlew build
and ./gradlew publish
, but the artifact doesn't get published.
I see this:
> Task :publish UP-TO-DATE
> Task :lending-ear:publish UP-TO-DATE
> Task :lending-framework:publish UP-TO-DATE
> Task :lending-pd:publish UP-TO-DATE
> Task :lending-si:publish UP-TO-DATE
> Task :lending-ui:publish UP-TO-DATE
I am guessing this is publishing locally (to local repository) and not artifactory, I'm running this in Jenkins in a scripted pipeline, how do I make it push to artifactory? I would want to push all sub modules into the artifactory.
Upvotes: 0
Views: 773
Reputation: 6073
You have 2 options:
Option 1: Use the Jenkins Artifactory plugin scripted pipelines Gradle job. This approach is the recommended and the easiest one.
Basic example:
def rtGradle = Artifactory.newGradleBuild()
rtGradle.deployer repo: 'libs-release-local', server: server
rtGradle.resolver repo: 'jcenter', server: server
rtGradle.run tasks: 'artifactoryPublish'
See relevant documentation here and full example here.
Option 2: Use the Gradle Artifactory plugin.
See relevant documentation here and full example here.
Upvotes: 1