从pom.xml中未能解析的依赖项

huangapple go评论87阅读模式
英文:

dependencies from pom.xml not being resolved

问题

我正在尝试在IntelliJ中创建一个Maven项目,用于使用ANTLR创建解析器。以下是我的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mua</groupId>
    <artifactId>json-parser-java-antlr</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Json parser Java ANTLR</name>
    <packaging>jar</packaging>
    <description>Trying to create a parser using ANTLR in Java, as facing problems with LLVM</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-runtime</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.directory.studio</groupId>
            <artifactId>org.apache.commons.io</artifactId>
        </dependency>
    </dependencies>
</project>

当我点击“导入更改”时,加载仅需1-2秒即可完成。但是,如果我尝试从org.apache.commons.collections4.MapUtils导入MapUtils,它会显示无法解析common,尽管我已经添加了<groupId>org.apache.commons</groupId>的依赖。

我在Maven项目创建和管理方面还是新手。

所以,问题出在哪里,我如何解决这个问题?

我研究了一些pom.xml文件,并找到了一个parent属性。不知道如何配置它。

英文:

I'm trying to create a maven project in intellij, to create a parser in antlr. Here is my pom.xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.mua&lt;/groupId&gt;
    &lt;artifactId&gt;json-parser-java-antlr&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;Json parser Java ANTLR&lt;/name&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;description&gt;Trying to create a parser using ANTLR in Java, as facing problems with LLVM&lt;/description&gt;
    &lt;properties&gt;
        &lt;java.version&gt;11&lt;/java.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.antlr&lt;/groupId&gt;
            &lt;artifactId&gt;antlr4-runtime&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
            &lt;artifactId&gt;commons-collections4&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.directory.studio&lt;/groupId&gt;
            &lt;artifactId&gt;org.apache.commons.io&lt;/artifactId&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/project&gt;

When I click on import changes, it loads for just 1-2 seconds then done. But if I try to import MapUtils from org.apache.commons.collections4.MapUtils it says it can't resolve common, although I added in &lt;groupId&gt;org.apache.commons&lt;/groupId&gt; dependency.

I'm new in maven project creation and management.

So, what is the problem here and how can I resolve this problem ?

I studied some pom.xml and found a parent attribute. No idea how to configure that.

答案1

得分: 0

我的 Eclipse 编辑器显示:

```lang-none
项目构建错误:缺少 org.antlr:antlr4-runtime:jar 的 'dependencies.dependency.version'。
项目构建错误:缺少 org.apache.commons:commons-collections4:jar 的 'dependencies.dependency.version'。
项目构建错误:缺少 org.apache.directory.studio:org.apache.commons.io:jar 的 'dependencies.dependency.version'。

由于它不知道您想要的这些依赖项的版本,因此没有任何依赖项能够正常工作。

在没有“父”POM 的情况下,指定依赖项而不包含版本信息是不可行的。您并没有使用“父”POM,因此版本是必需的。


<details>
<summary>英文:</summary>

My Eclipse editor shows:

```lang-none
Project build error: &#39;dependencies.dependency.version&#39; for org.antlr:antlr4-runtime:jar is missing.
Project build error: &#39;dependencies.dependency.version&#39; for org.apache.commons:commons-collections4:jar is missing.
Project build error: &#39;dependencies.dependency.version&#39; for org.apache.directory.studio:org.apache.commons.io:jar is missing.

None of the dependencies work, because it doesn't know which version of them you want.

Specifying dependencies without a version is something you do when you have a parent pom. You don't, so versions are mandatory.

答案2

得分: 0

你可以尝试在你的 pom.xml 文件中添加特定版本的 antlr。如果你也在使用 antlr 插件,确保你使用的 antlr 运行时版本与插件内置版本相同。

英文:

You could try adding a specific version of antlr to your pom.xml. And if you are using the antlr plugin as well, make sure the version of antlr run-time you are using is the same as the built-in version of the plugin.

huangapple
  • 本文由 发表于 2020年4月5日 15:35:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/61039430.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定