Classpath.asPath + Classpath.asPath

Hi,

The possible bug is when concatenate two Classpath.asPath the result does not show the first dependency of the second Classpath.asPath.

Explain with example:

buildscript {
	dependencies {
		classpath	'buildscript:buildscript-first:1.0.0',
				'buildscript:buildscript-second:2.0.0'
	}
}

configurations {
	provided
}

dependencies {
	provided 'provided:provided-first:1.0.0'
}

task show << {
	println configurations.provided.asPath + buildscript.configurations.classpath.asPath
}

The output of task show is:
{classpath=C:\userCachesFolder\provided-first-1.0.0.jar;C:\userCachesFolder\buildscript-second-2.0.0.jar}

Expected would be:
{classpath=C:\userCachesFolder\provided-first-1.0.0.jar;**C:\userCachesFolder\buildscript-first-1.0.0.jar;**C:\userCachesFolder\buildscript-second-2.0.0.jar}

P.S.: If this not a bug … notice that I’m newbie in gradle wolrd. Probably I don’t using correctly this methods.

Hey Jaume,

Two things here:

Every dependency needs to be prefixed with a scope (not comma separated as you did)

dependencies {
  classpath 'buildscript:buildscript-first:1.0.0'
  classpath 'buildscript:buildscript-second:2.0.0'
}

And if you want a path that is the sum of two configurations, it would be simpler and less error prone to do:

configOne.plus(configTwo).asPath

Cheers,
Stefan

It’s perfectly acceptable to pass a collection of dependencies in a single statement.

First at all, thanks for your replies.

I revised the issue and contrasted with the Stefan’s response

configOne.plus(configTwo).asPath

The real issue of the asPath + asPath is not lost an element, it seems does not concatenate correctly the “,” separators.

Let’s go with the same example again:

buildscript {
	dependencies {
		classpath	'buildscript:buildscript-first:1.0.0',
				'buildscript:buildscript-second:2.0.0'
	}
}

configurations {
	provided
}

dependencies {
	provided 'provided:provided-first:1.0.0'
}

task show1 << {
	println classpath:configurations.provided.asPath + buildscript.configurations.classpath.asPath
}

task show2 << {
    	println classpath:configurations.provided.plus(buildscript.configurations.classpath).asPath
    }

Notice the difference between my first post:
println **classpath:**configurat…

show1 output:
{classpath=C:\userCachesFolder\provided-first-1.0.0.jarC:\userCachesFolder\buildscript-first-1.0.0.jar;C:\userCachesFolder\buildscript-second-2.0.0.jar}

show2 output:
{classpath=C:\userCachesFolder\provided-first-1.0.0.jar;C:\userCachesFolder\buildscript-first-1.0.0.jar;C:\userCachesFolder\buildscript-second-2.0.0.jar}

Comparing “;” separators between outputs to find out the error with the show1 out using asPath + asPath

If you do asPath + asPath, you are just concatenating two Strings. Of course the separator is missing in that case :slightly_smiling:

That’s why I proposed to add the configurations first and only call asPath on the result.

Ok, understood.
So this is not a bug.
It’s only a newbie fault :sweat:
I suppose this topic could be closed.