我如何依赖Maven版本中的所有工件? [英] How do I get depend on all artifacts from a group of a version from maven?

查看:94
本文介绍了我如何依赖Maven版本中的所有工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的新手,我正在尝试首次构建一个项目.我想写一些依赖于Apache Lucene的代码.这是我要获取的清单Maven中的工件.

I'm new to Maven and I'm trying to build a project for the first time. I want to write some code that depends on apache lucene. Here's a list of artifacts in maven that I'm trying to get.

除了明确列出每个工件之外,还有什么方法可以依靠给定版本的所有工件吗?我试过了:

Is there any way instead of explicitly listing each artifact, I could simply depend on all artifacts of a given version? I tried this:

<dependency>
  <groupId>org.apache.lucene</groupId>
  <artifactId>*</artifactId>
  <version>3.6.1</version>
</dependency>

这给了我错误

值为的org.apache.lucene::jar的

'dependencies.dependency.artifactId'与有效的ID模式不匹配. @第19行,第19列

'dependencies.dependency.artifactId' for org.apache.lucene::jar with value '' does not match a valid id pattern. @ line 19, column 19

当我明确声明依赖项时,我可以验证是否可以下载依赖项. IE浏览器可以正常工作:

I can verify that I can download dependencies when I explicitly state them. IE this works fine:

<dependency>
  <groupId>org.apache.lucene</groupId>
  <artifactId>lucene-core</artifactId>
  <version>3.6.1</version>
</dependency>

我意识到依赖于lucene中的所有内容可能不是最优的,但是为了做一些快速而又肮脏的事情,我讨厌不得不手动填充所有这些小的lucene库.在Maven中获取大量相关依赖项的典型做法是什么?

I realize depending on everything in lucene is probably sub-optimal, but for doing something quick-and-dirty I'd hate to have to manually populate all these little lucene libraries. What is the typical practice for getting a large set of related dependencies in maven?

推荐答案

简短答案:您不能.请记住,您只需执行一次此操作,以后就可以简单地复制粘贴依赖项(不过不是很干).还可以考虑创建一个原型,该原型将快速创建具有所有必需依赖关系的骨架(用于快速和肮脏的项目).

Short answer: you can't. Remember you just do this once and later you can simply copy-paste dependencies (not very DRY though). Also consider creating an archetype that will quickly create a skeleton with all required dependencies (for quick and dirty projects).

更长的答案:好的,您可以解决此问题.使用以下命令创建单独的pom.xml:

Longer answer: well, you can work around that. Create a separate pom.xml with:

<packaging>pom</packaging>

并手动在那里声明所有Lucene依赖项.一劳永逸.稍后,您可以简单地向您的pom.xml添加一个依赖项(即在那里定义的groupId/artifactId/version),该依赖项将可传递地包括该pom.xml的所有依赖项.

and declare all Lucene dependencies there manually, one after another. Once and for all. Later you can simply add a dependency to your pom.xml (that is to groupId/artifactId/version defined there) which will transitively include all dependencies of that pom.xml.

谈论传递性:如果您依赖于maven中的JAR,并且该JAR具有其他依赖项,则您将隐式获得该传递性依赖项.检查Lucene pom,也许仅导入其中几个并依靠传递依赖项就足够了吗?

Talking about transitivity: if you depend on a JAR in maven and that JAR has other dependencies, you get that transitive dependencies implicitly. Examine Lucene poms, maybe it's enough to import few of them and rely on transitive dependencies?

这篇关于我如何依赖Maven版本中的所有工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆