Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

java - Gradle : how to translate "type" and "scope" from Maven dependency?

my Java project has a dependency in Maven like this :

    <dependency>
        <groupId>com.dependency</groupId>
        <artifactId>some-artifact</artifactId>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency> 

but when I write this in gradle, it does not recognize and I found no jar :

implementation 'com.dependency:some-artifact'

I wonder the reason is that I have to specify type and scope also, but I don't know what is the gradle equivalent to these two ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Gradle equivalent of scope is called configuration. The configuration that is equivalent to Maven's test scope is testImplementation.

There is no equivalent to Maven's type configuration in Gradle. However, there're classifier and extension. The classifier for test-jar is tests (according to the Maven docs).

Putting it all together, and for demonstration purposes assuming the version of the dependency is 1.0.0, you should declare the dependency like this:

testImplementation 'com.dependency:some-artifact:1.0.0:tests'

Further reading:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[6] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...