简体   繁体   English

不同的依赖管理者(例如Maven,Gradle)依赖语法之间的映射

[英]Mapping between different depencendy managers' (e.g. Maven, Gradle) dependency syntax

When I was browsing MvnRepository , I noticed a pattern. 当我浏览MvnRepository时 ,我注意到了一个模式。 For example if I want to use Spring Framework: 例如,如果我想使用Spring Framework:

Using Maven I need to add: 使用Maven我需要添加:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6.SEC03</version>
</dependency>

Using Gradle I need to add: 使用Gradle我需要添加:

'org.springframework:spring:2.5.6.SEC03'

So I came to the conclusion that if groupId = A , artifactId = B , version = C in Maven, I have to express it like 'A:B:C' in Gradle. 所以我得出的结论是,如果groupId = AartifactId = B ,在Maven中版本= C ,我必须在Gradle中将其表达为'A:B:C' I noticed a similar pattern for Ivy, Grape, Buildr, SBT, Leiningen syntax. 我注意到Ivy,Grape,Buildr,SBT,Leiningen语法的类似模式。

Is it always the rule or only an MvnRepository thing? 它总是规则还是只有MvnRepository的东西? For example, here is JLIBSVM which can be found in a custom respository, and on the webpage it is only given how to use it with Maven. 例如,这里是可以在自定义存储库中找到的JLIBSVM ,并且在网页上仅给出了如何将其与Maven一起使用。 Is it compatible with all these other dependency managers? 它是否与所有其他依赖管理器兼容?

You can also use this syntax in Gradle: 您还可以在Gradle中使用此语法:

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
}

And there are other variations like this: 还有其他类似的变化:

dependencies {
    compile (
        [group: 'foo', name: 'foo', version: '0.1'],
        [group: 'bar', name: 'bar', version: '0.1']
    )
}

Also, not all sections are always required. 此外,并非所有部分都是必需的。 For example if you just have a jar file in a flat directory on your system, you can say: 例如,如果您的系统上的平面目录中只有一个jar文件,则可以说:

runtime name: 'name'

Note the jar prefix is omitted. 请注意, jar前缀被省略。

Gradle and most other dependency managers support declaring dependencies that live in a Maven repository because Maven is ubiquitous. Gradle和大多数其他依赖管理器支持声明存在于Maven存储库中的依赖关系,因为Maven无处不在。 The project you mention is indeed hosted in a Maven repository, just not the Maven Central that you may be used to. 您提到的项目确实托管在Maven存储库中,而不是您可能习惯的Maven Central。 When using Gradle for example you have to indicate which Maven repository you want to use in the repositories section. 例如,在使用Gradle时,您必须在repositories部分中指明要使用的Maven存储repositories

是的,尽管周围还有一些修饰符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何声明Maven / Java库,例如JFreeChart,作为依赖? - How to declare Maven/Java library, e.g. JFreeChart, as dependency? Maven:在部署上使用不同的插件配置 - Maven: Using different plugin configurations on e.g. deploy 编译项目(:dependency)`Maven依赖项的Gradle映射? - Gradle mapping for `compile project(:dependency)` maven dependencies? 运行时相关性(例如,连接池)和类路径? - Runtime dependency (e.g. connection pooling) and classpath? 如何在Gradle中发布以编程方式操作(例如,仪器化的)罐子? - How to publish programmatically manipulated (e.g. instrumented) jars in Gradle? Docker的Maven插件(例如,与所需的数据库一起运行) - maven plugin for docker (e.g. to run with needed db) 将多个jar文件上传到Maven存储库(例如Archiva) - Upload multiple jar files to maven repository (e.g. Archiva) 如何对 Maven 依赖项进行故障排除(例如,在 ClassNotFoundException 的情况下) - How to troubleshoot Maven dependencies (e.g. in case of a ClassNotFoundException) 依赖罐版本在Maven和Gradle构建中有所不同 - Dependency jars versions different in maven and gradle build 如何在 Bitrise 上运行 Maven / JVM(例如 Appium + Saucelas / Selenium + Browserstack)测试自动化 - How to run Maven / JVM (e.g. Appium + Saucelabs / Selenium + Browserstack) Test Automation on Bitrise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM