dependency with file separator not resolving in gradle 6.0 version - gradle

I am upgrading my spring boot project to gradle 6.0. After upgrading to gradle 6.0 below dependency is not resolving. Is there anything changed with gradle 6.0 dealing with file separator. Below are the details.
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=http://repository.zoom.com:8081/artifactory/gradle-distributions/gradle-4.10.3-bin.zip
distributionUrl=http://repository.zoom.com:8081/artifactory/gradle-distributions/gradle-6.0-bin.zip
dependencies.gradle
configurations {
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
repositories {
maven { url 'http://repository.zoom.com:8081/artifactory/prerelease' }
maven { url 'http://repository.zoom.com:8081/artifactory/public' }
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-amqp")
implementation('com/zoom/ans:complete-order:dmz.100')
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
gradle.properties
group=com.zoom.order
projectVersion=1
# Dependencies
springBootVersion=2.1.3.RELEASE
springBootGradlePluginVersion=2.1.3.RELEASE
build.gradle
buildscript {
repositories {
maven { url "http://repository.zoom.com:8081/artifactory/internal-artifacts" }
maven { url "http://repository.zoom.com:8081/artifactory/plugins-release" }
maven { url "http://repository.zoom.com:8081/artifactory/public" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootGradlePluginVersion}"
}
}
// Community Plugins
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = projectVersion + '.' + version;
// Project plugins
apply from: "${projectDir}/gradle/dependencies.gradle"
// Spring Boot Properties
bootRun {
systemProperties = [ 'spring.config.location' : "file:src/main/config/runtime/local/", 'ExstreamPass_ExitCodeThreshold':8,
'logging.config' : "$projectDir/src/main/config/runtime/local/log4j2.json",
'LOG_PATH' : 'C:/logs' ]
jvmArgs = [ "-Dlogging.config=$projectDir/src/main/config/runtime/local/log4j2.json" ]
}
task qualify(dependsOn: [check, test]) {
doLast{ println project.name + ' : qualified' }
}
below is the grale build exception
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find com/zoom/ans:complete-order:dmz.100.
Required by:
project :
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileJava'.
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:374)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:361)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:354)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:340)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':compileClasspath'.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.java:1293)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$2300(DefaultConfiguration.java:140)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.visitFiles(DefaultConfiguration.java:1270)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.visitStructure(DefaultConfiguration.java:1263)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.visitStructure(DefaultConfiguration.java:504)
at org.gradle.api.internal.file.CompositeFileCollection.visitStructure(CompositeFileCollection.java:181)
at org.gradle.internal.fingerprint.impl.DefaultFileCollectionSnapshotter.snapshot(DefaultFileCollectionSnapshotter.java:49)
at org.gradle.internal.fingerprint.impl.AbstractFileCollectionFingerprinter.fingerprint(AbstractFileCollectionFingerprinter.java:46)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.lambda$visitInputFileProperties$1(ExecuteActionsTaskExecuter.java:306)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$fingerprintInputFiles$3(CaptureStateBeforeExecutionStep.java:192)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.visitInputFileProperties(ExecuteActionsTaskExecuter.java:304)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.fingerprintInputFiles(CaptureStateBeforeExecutionStep.java:188)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionState(CaptureStateBeforeExecutionStep.java:150)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$captureExecutionStateOp$1(CaptureStateBeforeExecutionStep.java:104)
at org.gradle.internal.execution.steps.BuildOperationStep$1.call(BuildOperationStep.java:40)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.internal.execution.steps.BuildOperationStep.operation(BuildOperationStep.java:37)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionStateOp(CaptureStateBeforeExecutionStep.java:103)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$execute$0(CaptureStateBeforeExecutionStep.java:78)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:78)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:174)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:166)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
... 23 more
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com/zoom/ans:complete-order:dmz.100.
Required by:
project :
Below are dependency library project configuration details. Below one is publishing the jar (complete-order:dmz.100) to repository.
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'http://repository.zoom.com:8081/artifactory/maven' }
maven { url 'http://repository.zoom.com:8081/artifactory/plugins-release' }
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2"
classpath('se.transmode.gradle:gradle-docker:1.2')
classpath 'com.zoom.ebe:internal-artifacts:+'
classpath 'com.zoom.ebe:jar-stamper:+'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'docker'
apply plugin: 'maven-publish'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'jacoco'
apply plugin: 'org.sonarqube'
apply plugin: 'build-dashboard'
apply plugin: 'project-report'
apply plugin: 'checkstyle'
apply plugin: 'com.zoom.ebe.jar-stamper'
apply plugin: 'com.zoom.ebe.internal-artifacts'
apply plugin: 'groovy'
def currentJvm = org.gradle.internal.jvm.Jvm.current()
println currentJvm
sourceCompatibility = 1.8
targetCompatibility = 1.8
project.ext {
app_name='ANS'
build_date=new Date().format("yyyyMMddHHmm")
release_number='R1.0'
groupId="com.zoom.ans"
rc_build="${System.env.BUILD_NUMBER}" //look for BUILD_NUMBER in env (set by Jenkins)
buildID = "ANS_CompleteOrder_Full"
fortify_build_id='ANS_CompleteOrder_Full'
sonar_projectkey='ANS_CompleteOrder'
sonar_projectname='ANS Complete Order'
}
group 'com.zoom.ans'
repositories {
mavenCentral()
maven { url 'http://repository.zoom.com:8081/artifactory/internal-artifacts' } // this repository is designed for internal-artifacts publishing
maven { url 'http://repository.zoom.com:8081/artifactory/zoom-local' }
maven { url 'http://repository.zoom.com:8081/artifactory/prerelease' }
maven { url 'http://repository.zoom.com:8081/artifactory/external' }
maven { url 'http://repository.zoom.com:8081/artifactory/maven' }
ivy {
url 'http://repository.zoom.com:8081/artifactory/maven'
layout "pattern", {
artifact "[organisation]/[module]/[revision]/[type]/[artifact]-[revision](-[classifier]).[ext]"
ivy "[organisation]/[module]/[revision]/ivy-[revision](-[classifier]).xml"
}
}
}
task buildDocker(type: Docker, dependsOn: build) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
findbugsMain { ignoreFailures = false }
findbugsTest { ignoreFailures = true }
pmdMain { ignoreFailures = false }
pmdTest { ignoreFailures = true }
checkstyleMain {
source = 'src/main/java'
}
checkstyle{
ignoreFailures = true
showViolations = false
}
tasks.withType(FindBugs) {
reports {
xml.enabled = true
html.enabled = !xml.enabled
}
}
// Additional dependency configurations.
configurations {
fortify { extendsFrom compile }
}
clean {
delete fileTree(dir: "build/")
delete file("dist/")
}
dependencies {
checkstyle "com.puppycrawl.tools:checkstyle:8.14"
fortify "com.fortify:sourceanalyzer:3.90"
compile "org.slf4j:slf4j-api:1.7.+"
compile 'com.google.code.findbugs:annotations:3.0.1'
compile 'org.beanio:beanio:2.0.7'
compile 'commons-lang:commons-lang:2.4'
compile "commons-io:commons-io:2.4"
compile 'com.amazonaws:aws-java-sdk-s3:1.9.0'
compile 'com.zoom.etc.storage:payx-object-storage:2.0.x.master.+'
compile 'com.zoom.traceability:zoom-traceability-mark-library:2.1.4.master.+'
compile 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
compile 'org.apache.logging.log4j:log4j-api:2.11.1'
//Jackson -JSON parser for java
//compile 'com.fasterxml.jackson.core:jackson-databind:2.0.1'
testCompile 'org.codehaus.groovy:groovy-all:2.4.+'
testCompile "org.easyb:easyb:0.9.6"
testCompile "org.easyb:easyb-junit:0.5.3"
testCompile "junit:junit:4.+"
testCompile "org.easymock:easymock:3.+"
testCompile "org.slf4j:slf4j-simple:1.7.+"
testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.7.+"
}
task fortifySetup(dependsOn: clean) << {
ant.properties['build.compiler']='com.fortify.dev.ant.SCACompiler'
ant.typedef(name: 'sca', classname: 'com.fortify.dev.ant.SourceanalyzerTask',
classpath: configurations.fortify.asPath)
}
task fortifyReport(dependsOn: compileJava) << {
ant.sca(//buildid: buildID ,
jdk: "1.8",
debug:true,
verbose:true,
failonerror:true,
scan: true,
logFile:file("$buildDir/reports/fortify/Fortify.log"),
resultsFile:file("$buildDir/reports/fortify/${fortify_build_id}.fpr")
)
{
fileset(dir: 'src/main') {
include(name: '**/*.java')
}
}
}
sonarqube {
properties {
property "sonar.host.url", "${System.env.SONAR_URL}"
property "sonar.jdbc.url", "${sonar_jdbc_url}"
property "sonar.jdbc.driverClassName", "${sonar_jdbc_driver}"
property "sonar.jdbc.username", "${sonar_jdbc_username}"
property "sonar.jdbc.password", "${sonar_jdbc_password}"
property "sonar.projectKey", sonar_projectkey
property "sonar.projectName", sonar_projectname
}
}
task easyb << {
ant.taskdef(name: "easyb", classname:"org.easyb.ant.BehaviorRunnerTask", classpath: sourceSets.test.runtimeClasspath.asPath)
ant.easyb( classpath: sourceSets.test.runtimeClasspath.asPath, failureProperty:'easyb_failed' ) {
report( location:"${project.testResultsDir}/story.html", format:"html" )
behaviors( dir: "src/test/behaviors" ) {
include( name:"**/*.story" )
}
}
ant.fail( if:'easyb_failed', message: 'Failures in easyb stories' )
println "EasyB Story report can be found at ${project.testResultsDir}/story.html"
}
task runVolumeTest (dependsOn: 'classes', type: JavaExec) {
main = 'CoreAdvancedPrintFlowOrchestratorImplVolumeTest'
classpath = sourceSets.test.runtimeClasspath
}
//make sure tests use test resources and test behaviors where TAF utils exist.
sourceSets {
test {
resources {
srcDir "src/test/resources"
srcDir "src/test/behaviors"
}
}
}
// Pre-Release Artifactory Publishing
publishing{
repositories {
maven { url 'https://repository.zoom.com:8081/artifactory/prerelease' }
}
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar {
classifier "sources"
}
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.java
}
artifacts {
archives sourcesJar
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http://repository.zoom.com:8081/artifactory/gradle-distributions/gradle-4.5.1-bin.zip
any suggestion how to resolve this.

The dependency notation 'com/zoom/ans:complete-order:dmz.100' looks rather unusual. As already mentioned in the comments, my hunch is that it just happened to work with the older Gradle version, was never officially supported and hence broke with Gradle 6 now.
There are still many pieces missing to be absolutely certain but given that your dependency library seems to be published with group 'com.zoom.ans', I would expect it to be resolvable using the following dependency declaration:
dependencies {
implementation('com.zoom.ans:complete-order:dmz.100')
}
If it doesn’t work, then you should search the prerelease repository of your Artifactory server at http://repository.zoom.com:8081/artifactory/ for artifacts containing complete-order, complete-order-dmz.100 or the like in their names. Usually you can then browse the repository tree to find the desired JAR file, select it and find a section “Dependency Declaration” on the right where you can select “Gradle” to see the correct group name, etc. (should look similar to this).

Related

Gradle spotbugs plugin

I am new to Gradle and trying to configure Spotbugs for my Spring Boot multi module project.
In my parent, build.gradle,
buildscript {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${versionSpringBoot}"
}
}
plugins {
id 'com.github.spotbugs' version '1.6.8'
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'pmd'
apply plugin: 'jacoco'
dependencyManagement {
imports {
}
}
configurations{
}
sourceCompatibility = '15'
targetCompatibility = '15'
dependencies {
}
pmd {
consoleOutput = true
toolVersion = "${versionPmd}"
sourceSets = [sourceSets.main]
ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"]
}
spotbugs {
toolVersion = "${versionSpotBugs}"
sourceSets = [sourceSets.main]
}
jacoco {
toolVersion = "${versionJacoco}"
}
jacocoTestReport {
reports {
xml.enabled = true
}
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
}
Spotbugs doesn't run on running
./gradlew check
The main issue with your build configuration is that you apply the SpotBugs plugin only to your root project. The following configuration solves that (leaving out configurations that are unrelated to the SpotBugs plugin for brevity):
plugins {
// we don’t need to *apply* the plugin to the root project, do we?
id 'com.github.spotbugs' version '4.7.0' apply false
}
subprojects {
apply plugin: 'java'
// this is the most important part, applying the plugin to the subprojects,
// too:
apply plugin: 'com.github.spotbugs'
spotbugs {
toolVersion = '4.2.2'
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
}
With this configuration, ./gradlew check also runs the SpotBugs tasks of subprojects (tested with Gradle 6.8.3).
Please note that I’ve also made a few other changes:
I’m using a recent version of the plugin as the one that you’ve used (1.6.8) is several years old and doesn’t seem to work with recent versions of Gradle.
I’ve removed the sourceSets configuration which is not needed and doesn’t work anyway.
I’ve replaced the fully qualified name of the task type with an up-to-date version.
I hope this helps. Please let me know if you’re stuck with the old SpotBugs version for some reason; knowing the Gradle version that you use would help in that case.
The below works (some adjustments to make it work locally)
gradle - 6.5.1
buildscript {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.4.3"
}
}
plugins {
id 'com.github.spotbugs' version '4.7.0'
}
import com.github.spotbugs.snom.SpotBugsTask
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
}
}
configurations{
}
sourceCompatibility = '15'
targetCompatibility = '15'
dependencies {
}
spotbugs {
toolVersion = '4.2.1'
}
tasks.withType(SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
}

Gradle: create .jar from .class files and include it in EAR_dir/lib when EAR is built

You'd think this'd be easy enough. Gradle/Maven were designed specifically to get rid of build nightmares. And yet... I have scoured the web, including SO. I would prefer to be using Maven but alas this is not in my control.
My master build.gradle file looks like this:
buildscript {
repositories {
maven { url "https://aaa.com/xxxx/aaa-mvn" }
}
dependencies {
{redacted}
classpath "com.aaa.plugin.gradle:module-plugin:1.+"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.4"
}
}
apply plugin: 'maven-publish'
apply plugin: {redacted}
apply plugin: {redacted}
apply plugin: 'build-defaults'
apply plugin: 'module-plugin'
apply plugin: 'war'
description = 'xxxxxx'
defaultTasks 'build','install'
dependencies {
jbossModule(group: 'com.aaa.bbbb', name: 'inf-jdbc', version: '3.0.2')
}
artifactory {
publish {
repoKey=version.endsWith("SNAPSHOT") ? 'aaa-mvn-dist-snapshots' : 'aaa-mvn-dist'
defaults {
publications('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact project(':xxxEAR').ear
}
}
}
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
This is gradle.build for my .war. I have a .war inside an .ear.
description = 'Pricing'
buildscript {
repositories {
maven { url "https://xxx.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath {redacted}
classpath {redacted}
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jacoco'
apply plugin: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
apply plugin: 'maven'
apply plugin: 'maven-publish'
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
war {
archiveName 'xxxx.war'
}
dependencies {
compile {redacted}
compileOnly group: 'javax', name: 'javaee-api', version:'7.0'
testCompile "junit:junit:4.12"
compile 'io.swagger:swagger-annotations:1.5.10'
compile(group: 'com.aaa.inf', name: 'inf-jdbc', version: '3.0.2', classifier: 'sources')
compile(group: 'com.aaa.inf', name: 'inf-throttle', version: '3.0.1')
compile(group: 'com.ibm.db2', name: 'db2jcc', version: '3.64.133')
compile {redacted}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
}
The build.gradle file for my .ear is:
description = 'xxxxx'
buildscript {
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.5"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:openapi-generator-gradle-plugin:1.+"
}
}
apply plugin: 'ear'
apply plugin: 'maven'
apply from: 'build.local-jboss.gradle'
apply plugin: 'maven-publish'
apply plugin: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
configurations{
gen
}
dependencies {
deploy project (path: ":pricingWAR", configuration: 'archives')
earlib 'com.aaa.inf:inf-api-auth:1.4.+'
earlib {redacted}
earlib group: 'javax.security.enterprise', name: 'javax.security.enterprise-api', version: '1.0'
earlib (group: {redacted}) {
exclude group: 'javax.security.dddddd'
}
gen "io.swagger:swagger-codegen:2.2.2"
}
artifacts{
archives ear
}
repositories {
maven {
url "https://xxxx.aaa.com/artifactory/aaa-mvn"
}
}
task cleanVolumes(type: Delete) {
delete fileTree(dir: "./volumes/deployments/")
}
task copyEar(type: Copy) {
tasks.cleanVolumes.execute()
from "build/libs"
into "${project.projectDir}/volumes/deployments"
fileMode = 0644
}
build.finalizedBy(generateSwagger)
swaggerConfig {
archive = ear.archivePath
outputFormat = "JSON"
outputPath = project.buildDir.toString() + "/swagger"
}
Just looking to do this: .jar up the .class files compiled in my business classes and add them to EAR_file\lib.
I've gone so far as to try to use Gradle's native Groovy nature to write code that builds the .jar and moves it into EAR_file\lib. This of course is ridiculous. And worse still, it does not quite work. Paired with auto-deploy there are timing issues.
Some of you no doubt are wincing.
To save me from such insanity, please let me know what you know about this. I have of course tried various permutations of:
apply plugin: 'java'
...
jar {
...
}
to no avail.
Thank you in advance.
Finally have it working after helpful input from coworkers. For others' benefit here is the whole thing it ended up as:
In build.gradle in the EAR project level:
// My project is named: xxx-svc and the .war subproject is named pricing-theAPI
dependencies {
deploy project (path: ":xxx-theAPI", configuration: 'archives') // This was here already
earlib project(path: ":xxx-theAPI", configuration: 'customJar') // This is new
}
In build.gradle in the WAR project level:
configurations {
customJar
}
task doJar(dependsOn:classes, type: Jar){
from sourceSets.main.output
include 'com/xyz/xxxxx/yyyyyy/zzzz/**' // See Note 1
}
artifacts {
customJar doJar
}
Note 1: I added this modifier b/c in my case I needed only the .class files at the given location in the .jar and in fact had to exclude all others. Note the Gradle docs have the modifier "include" misidentified. They call it "includes" but in fact it is "include".

Gradle changing module from nexus snapshot repo not updated

I have a problem with a snapshot artifact not being uploaded.
I'm using snapshot version. Atrifact is marked explicitly as changing: true and cacheChangingModulesFor is set to 0 seconds.
When i run --refresh-dependecies the artifact is redownloaded properly.
I found the problem while using gradle 2.9. But after upgrading to 2.14.1 the issue remains.
Below is my build.gradle file:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/plugins-release' }
}
// dependencies for plugins
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
jar {
baseName = 'someproject'
version = '0.0.1-SNAPSHOT'
}
war {
baseName = "someproject"
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
maven {
url 'http://nexus.example.com:8081/nexus/content/repositories/java-libs-snapshots/'
credentials {
username "someuser"
password "somepassword"
}
}
}
// enables to run with dev profile: $ gradle local bootRun
task local << {
bootRun.systemProperty 'spring.profiles.active', 'local'
}
bootRun {
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
dependencies {
compile 'mysql:mysql-connector-java'
compile 'org.springframework.boot:spring-boot-starter-web'
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
compile 'org.jadira.usertype:usertype.core:5.0.0.GA'
compile group: 'com.rometools', name: 'rome', version: '1.6.0'
compile group: 'org.jsoup', name: 'jsoup', version: '1.9.2'
compile 'org.hibernate:hibernate-search:5.5.3.Final'
compile 'org.projectlombok:lombok:1.16.6'
}
I think you maybe have the syntax for the changing dependency slightly wrong.
Can you try replacing:
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
with:
compile ("pl.example:name:0.7.6.1-SNAPSHOT"){ changing = true }
Can you also try adding a line to the resolutionStrategy for cacheDynamicVersionsFor as follows:
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}

Publish Java artifact to Maven Local with Gradle

I am facing a problem when trying to install a generated jar into my local Maven Repository. The message error just show me 'task 'publish' is not found'
I am using this Gradle Script:
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
jar {
baseName = 'mongofoundry'
version = '1.0.0'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Do you have some idea Why I am reading that error message?
Thanks.
UPDATED
Running the command as #RaGe mentioned, solved the problem:
gradle publishToMavenLocal
The correct task to publish artifacts to local maven is
gradle publishToMavenLocal
Check Maven locally
For developing and testing it is useful to check library locally
gradle settings for apply plugin: 'com.android.library' not apply plugin: 'java-library'(where you can use it by default)
apply plugin: 'maven-publish'
//simple settings
project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
//setGroupId groupId
setGroupId "com.company"
//setArtifactId artifactId
setArtifactId "HelloWorld"
version "1.1"
artifact bundleDebugAar
/* add a dependency into generated .pom file
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', 'com.company')
dependencyNode.appendNode('artifactId', 'HelloWorld-core')
dependencyNode.appendNode('version', '1.1')
}
*/
}
}
}
}
to run it using command line or find this command in Gradle tab
./gradlew publishToMavenLocal
Location
artefact will be added into .m2 folder
//Unix
~/.m2
//Windows
C:\Users\<username>\.m2
//For example
/Users/alex/.m2/repository/<library_path>/<version>/<name>.<extension>
build folder
<project_path>/build/outputs/<extension>
other repositories location
~/.gradle/caches/modules-2/files-2.1/<group_id>/<artifact_id>/<version>/<id>
//For example
/Users/alex/.gradle/caches/modules-2/files-2.1/com.company/HelloWorld/1.1/c84ac8bc425dcae087c8abbc9ecdc27fafbb664a
To use it add mavenLocal(). It is important to place it as a first item for prioritise it, which is useful for internal dependencies
buildscript {
repositories {
mavenLocal()
}
allprojects {
repositories {
mavenLocal()
}
}
and
dependencies {
implementation 'com.company:HelloWorld:+'
}
*Also remember if you use a kind of shared.gradle file (via apply from) you should set path which is relevant to project.gradle (not shared.gradle)
[iOS CocoaPod local]
This is how I did it with Kotlin DSL (build.gradle.kts) for my Android library:
plugins {
id("maven-publish")
// OR simply
// `maven-publish`
// ...
}
publishing {
repositories {
// Local repository which we can first publish in it to check artifacts
maven {
name = "LocalTestRepo"
url = uri("file://${buildDir}/local-repository")
}
}
publications {
// ...
}
}
You can create all the publications with the following command:
./gradlew publishAllPublicationsToLocalTestRepoRepository
Or just a single publication with this command:
./gradlew publishReleasePublicationToLocalTestRepoRepository
See Gradle documentations: Maven Publish Plugin for more information.
Add maven plugin to your project and then:
gradle clean install
Here is an alternative skeleton for Gradle 7.5.1 with Java 17
build.gradle
plugins {
id 'org.gradle.java'
id 'org.gradle.maven-publish'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'your-group'
artifactId = 'your-artifact'
version = "0.0.1"
from components.java
}
}
repositories {
mavenLocal()
}
}
Publishing
You can see more details on the publishing steps with --info
./gradlew --info publishToMavenLocal
Output Directory
Linux/macOS
/Users/<username>/.m2/repository/your-group/your-artifact/0.0.1
Windows
C:\Users\<username>\.m2\repository\your-group\your-artifact\0.0.1

Gradle Error: No method add() found for arguments

So I'm adding a custom plugin to Gradle, specifically jmeter. https://github.com/kulya/jmeter-gradle-plugin
I thought everything worked, but now this error is occuring:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\rstraubel\Documents\DataCentral\build.gradle' line: 21
* What went wrong:
A problem occurred evaluating root project 'DataCentral'.
> Could not find method add() for arguments [jmeterEditor, class com.github.kulya.gradle.plugins.jmeter.JmeterRunGuiTask] on task set.
Line 21 is just where I call plugin: 'jmeter'
Everything else specified in the github has been done. Any ideas? Thanks
Edit: Full Build.gradle
buildscript {
ext {
springBootVersion = '1.0.2.RELEASE'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone"}
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("com.github.kulya:jmeter-gradle-plugin:1.3.1-2.6")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'idea'
apply plugin: 'sonar-runner'
apply plugin: 'jmeter'
jar {
baseName = 'datacentral'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://m2.neo4j.org" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
compile "org.springframework.boot:spring-boot-starter-data- mongodb:${springBootVersion}"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.data:spring-data-mongodb"
compile "org.mongodb:mongo-java-driver:2.12.0-rc0"
compile "org.springframework.data:spring-data-rest-webmvc"
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
}
jmeterRun.configure {
jmeterTestFiles = [file("src/test/jmeter/TestCases.jmx")]
}
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://hawkeye.control-tec.com:9000"
property "sonar.jdbc.url", "jdbc:mysql://bluestreak.qualifier.control-tec.com:3306/sonar?useUnicode=true&characterEncoding=utf8"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar-pass"
property "sonar.projectKey", "com.controltec.incontrol.qualifier:Data-Central"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
Most likely, the jmeter plugin hasn't been updated to support Gradle 2.0. You can verify by trying with 1.12.

Resources