Gradle doesn't download dependency if folder name is same as artifact name

Hi,
I have some weird requirement where my folder (in which build.gradle exists) is same as the the artifact i need to download from artifactory. For ex:

abc
\build.gradle

build.gradle

dependencies {
    runtimeOnly "mygroup:abc:1.0"
}

Gradle is not downloading the jar, instead it says build skipped as no SOURCE found:

Is there a way to force download the jar though source doesn’t exist???

If that build in abc has project name abc and group mygroup, then normal conflict resolution kicks in.
So if the local project has the newer version than the published ones, it is selected. Depending on the concrete use-case you could e. g. temporary change the group of the project and after resolution change it back or similar hack-arounds.

Thanks for the inputs. Changing group name/version didnt work. Basically what i need is i want to copy dependencies to a folder called lib.

We maintain two structures in SVN. One have source code and the other have some kind of bin, conf , lib etc. In this case, unforntunately, both have same folder name i.e, source code also has name abc which generates jar abc-1.0.jar uploads to artifactory. The other path also has same name abc which just downloads the abc-1.0.jar from artifactory and prepares lib.

I tried the approach you suggested and couple of other approaches found over internet:
FYI: This is my full build.gradle.

ext {
	libsDir='lib'
}
/** tried changin the group **/
group="com.temp"

/** tried setting below flags, didnt work **/
//jar.enabled=false   
//build.enabled=false

dependencies {
    //runtimeOnly "mygroup:xyz:1.0"  // if i enable this, xyz jar getting downloaded and copied to lib
	runtimeOnly "mygroup:abc:1.0" // but this is not coming
}

configurations.all {
  resolutionStrategy {
   force "mygroup:abc:1.0" //i even tried this, but didnt work :(
  }
}

clean {
	delete fileTree(dir:"$libsDir", include: '**.jar')
}

tasks.register('copyDeps',Copy) {
		duplicatesStrategy = DuplicatesStrategy.EXCLUDE
		from configurations.runtimeClasspath
		into "lib" //this will be set by callers..
		doLast {
			println "dependencies copied"
		}
	}

build.finalizedBy(copyDeps)

Running gradle build generates below logs (fyi) :

Task :compileJava NO-SOURCE
Skipping task ‘:compileJava’ as it has no source files and no previous output files.
:compileJava (Thread[included builds,5,main]) completed. Took 0.005 secs.
Resolve mutations for :processResources (Thread[Execution worker,5,main]) started.
Resolve mutations for :processResources (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
:processResources (Thread[included builds,5,main]) started.

Task :processResources NO-SOURCE
Skipping task ‘:processResources’ as it has no source files and no previous output files.
:processResources (Thread[included builds,5,main]) completed. Took 0.001 secs.
Resolve mutations for :classes (Thread[Execution worker,5,main]) started.
Resolve mutations for :classes (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
:classes (Thread[included builds,5,main]) started.

Task :classes UP-TO-DATE
Skipping task ‘:classes’ as it has no actions.
:classes (Thread[included builds,5,main]) completed. Took 0.0 secs.
Resolve mutations for :jar (Thread[Execution worker,5,main]) started.
Resolve mutations for :jar (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
:jar (Thread[included builds,5,main]) started.

Task :jar SKIPPED
Skipping task ‘:jar’ as task onlyIf is false.
:jar (Thread[included builds,5,main]) completed. Took 0.0 secs.
Resolve mutations for :startScripts (Thread[Execution worker,5,main]) started.
Resolve mutations for :startScripts (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
:startScripts (Thread[included builds,5,main]) started.

Task :test NO-SOURCE
Skipping task ‘:test’ as it has no source files and no previous output files.
:test (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
Resolve mutations for :check (Thread[included builds,5,main]) started.
Resolve mutations for :check (Thread[included builds,5,main]) completed. Took 0.0 secs.
:check (Thread[Execution worker,5,main]) started.

Task :check UP-TO-DATE
Skipping task ‘:check’ as it has no actions.
:check (Thread[Execution worker,5,main]) completed. Took 0.0 secs.
Resolve mutations for :build (Thread[included builds,5,main]) started.
Resolve mutations for :build (Thread[included builds,5,main]) completed. Took 0.0 secs.
:build (Thread[Execution worker Thread 7,5,main]) started.

Task :build SKIPPED
Skipping task ‘:build’ as task onlyIf is false.
:build (Thread[Execution worker Thread 7,5,main]) completed. Took 0.0 secs.
Resolve mutations for :copyDeps (Thread[included builds,5,main]) started.
Resolve mutations for :copyDeps (Thread[included builds,5,main]) completed. Took 0.0 secs.
:copyDeps (Thread[Execution worker Thread 7,5,main]) started.
producer locations for task group 0 (Thread[included builds,5,main]) started.
producer locations for task group 0 (Thread[included builds,5,main]) completed. Took 0.0 secs.

Task :copyDeps NO-SOURCE
Skipping task ‘:copyDeps’ as it has no source files and no previous output files.
:copyDeps (Thread[Execution worker Thread 7,5,main]) completed. Took 0.001 secs.

Can you please suggest.

That cannot be your full build logic.
Because that would fail with not finding runtimeOnly configuration and you also have no plugins applied that would add things like compileJava or processResources or even build.
So you have some more build logic used and maybe that also sets the group again after you think you changed it.

Okay my bad
 forgot to share init.gradle


allprojects {
	apply plugin: 'java' //tried having 'application' as well but no luck..
	
	configurations {
		runtimeClasspath.transitive = false
	}

	repositories {
		maven {
			//println "svnbranch: $branch"
			url "myrepo1"
			url "myrepo2"
			
			allowInsecureProtocol = true
		}
	}
}

Can you provide a full MCVE? At least I cannot really reproduce what you describe from what you showed.

Thank you so much for guiding me to debug the issue in right direction. I created demo project to share to you but then while testing found that gradle just works without doing any thing. It just downloads the dependency despite folder having same name or not. GRADLE IS FLAWLESS :smiley:

Then i started finding out whats the issue with my jar. It seems issue with only “this” particular jar. If i create another folder same as another inhouse jar name, it just works without doing anything. It simply downloads the jar from artifactory and put it into lib. When i run build by setting the flag --refresh-dependencies , then i realized gradle not even trying to download the jar from artifactory. These are the logs i found this problematic jar and proper jar:

pqr.jar (proper one)

Task :copyDeps UP-TO-DATE
Cached resource http://myrepo/mygroup/pqr/1.0/pqr-1.0.pom is up-to-date (lastModified: Tue Sep 13 21:38:10 IST 2022).
Cached resource http://myrepo/mygroup/pqr/1.0/pqr-1.0.module is up-to-date (lastModified: Wed Dec 14 17:39:26 IST 2022).
Cached resource http://myrepo/mygroup/pqr/1.0/pqr-1.0.jar is up-to-date (lastModified: Wed Dec 14 17:39:26 IST 2022).

abc.jar (problematic one)

Task :copyDeps UP-TO-DATE
Cached resource http://myrepo/mygroup/abc/1.0/abc-1.0.pom is up-to-date (lastModified: Tue Sep 13 21:38:10 IST 2022).
Cached resource http://myrepo/mygroup/abc/1.0/abc-1.0.module is up-to-date (lastModified: Wed Dec 14 17:39:26 IST 2022).

Then drilled down further to find out whats the exact issue with this particular jar. Found this difference in pom.xml of this jar with other jars we have in the repo:
<packaging>pom</packaging>

whereas the other proper jar doesn’t have it.

Reason:
abc.jar is a spring boot jar which we are we uploading to artifactory using this below piece of code:

publishing {
    publications {
        mavenJava(MavenPublication){
            // bootJar is the default build task configured by Spring Boot
            artifact bootJar
        }
    }
}

This is creating pom.xml with <packaging>pom</packaging> in artifactory. So this is the culprit :smiley:

Not sure how to fix this logic.

You should practically never use artifact on publications, like you should never use explicit dependsOns except if a lifecycle task is on the left-hand side.

Find for example at Upgrading your build from Gradle 6.x to the latest how to do it properly.