Gradle

Gradle doesn't support ivy configuration expression

Details

Description

In ivy's world, the configuration of a dependency is always more complex than a single word and will be a long expression.

The common and widely used one is that :

conf="compile->compile(*),master(*);runtime->runtime(*)"/>

For example, in the ivy file of easymock 3.0:

<dependencies>
		<dependency org="cglib" name="cglib-nodep" rev="2.2" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
		<dependency org="org.objenesis" name="objenesis" rev="1.2" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
		<dependency org="junit" name="junit" rev="4.8.1" force="true" conf="test->runtime(*),master(*)"/>
	</dependencies>

And also testng 6.1

<dependencies>
		<dependency org="ant" name="ant" rev="1.6.5" force="true" conf="optional->compile(*),master(*)"/>
		<dependency org="junit" name="junit" rev="3.8.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
		<dependency org="org.beanshell" name="bsh" rev="2.0b4" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
		<dependency org="com.google.inject" name="guice" rev="2.0" force="true" conf="provided->compile(*),provided(*),runtime(*),master(*)"/>
		<dependency org="com.beust" name="jcommander" rev="1.12" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
		<dependency org="org.yaml" name="snakeyaml" rev="1.6" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
	</dependencies>

We can see that almost even configuration is not simple like "compile" or "runtime", but a complex expression.This feature is a important, powerful and widely used in ivy's world.

But in gradle's configuration, this configuration expression is not supported!! In gradle, it only supports a single word of configuration like "compile" or "runtime".Otherwise gradle will fail and report that the configuration (like 'compile,runtime') is not a valid configuration!

I checked the code of gradle and found the reason, in class DefaultIvyDependencyResolver :

private ResolveOptions createResolveOptions(Configuration configuration) {
        ResolveOptions resolveOptions = new ResolveOptions();
        resolveOptions.setDownload(false);
        resolveOptions.setConfs(WrapUtil.toArray(configuration.getName()));
        return resolveOptions;
    }

Be care to this line

resolveOptions.setConfs(WrapUtil.toArray(configuration.getName()));

In this method, the configuration name will be directly passed to ivy resolveOptions by a simply wrap from a String to a String[]. So when the configuration is 'compile,runtime', I expect that the ivy will handle two configurations as String[]{"compile", "runtime"} , but in fact gradle will pass a String["compile,runtime"] to ivy.

As a old ivy user, I feel very disappointed and regretful for this issue, because it is really very powerful and important.

I hope in the next release ASAP gradle will support some similar expression like

compile(*),master(*)

Activity

Hide
Sky Ao added a comment -

the is that "( * )"

Show
Sky Ao added a comment - the is that "( * )"
Hide
Sky Ao added a comment -

If there are something difficult in the implementation of expression 'compile( * )', we can implement the expression 'compile,runtime' at first.

Because this is very simple for gradle : just split the configuration by char ',' and set the result String[] to ivy(trim to get rid of whitespace?).

"resolveOptions.setConfs(configuration.getName().split(","));".

Show
Sky Ao added a comment - If there are something difficult in the implementation of expression 'compile( * )', we can implement the expression 'compile,runtime' at first. Because this is very simple for gradle : just split the configuration by char ',' and set the result String[] to ivy(trim to get rid of whitespace?). "resolveOptions.setConfs(configuration.getName().split(","));".

People

  • Assignee:
    Unassigned
    Reporter:
    Sky Ao
Vote (2)
Watch (2)

Dates

  • Created:
    Updated: