[英]IntelliJ cannot resolve symbol 3rd party jar with Maven
我有一个第三方JAR,我已经通过mvn install:install-file
命令创建了一个工件。 该工件已添加到项目中,并且模块的pom.xml
并已导入就可以了。
不幸的是,使用第3方JAR中的符号创建Java类仍然没有解决。 红色灯泡显示,并且没有“进口类别”的选项,正如我期望的那样。
我试图使缓存无效| 重新启动,但无济于事。
有任何想法吗?
编辑如果我不是安装编译JAR,符号得到解决。 为什么会这样呢?
编辑2添加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>
<packaging>pom</packaging>
<name>Sandbox</name>
<parent>
<groupId>com.x.y</groupId>
<artifactId>third-party-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.x.y.z</groupId>
<artifactId>thirdparty-z</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.x.y.thirdparty</groupId>
<artifactId>thirdparty-sources</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.x.y.thirdparty</groupId>
<artifactId>thirdparty-compiled</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
这个Maven项目文件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>
<!-- Parent POM best at the top -->
<!-- WANRING: Here you import the parent of 3th party. This is (almost) never correct!!! -->
<!-- For a simple project, which only exists of 1 set of classes and unit tests, you do -->
<!-- not need a parent POM. Only for multi module Maven project, you will have a parent -->
<!-- POM. Or for organisation wide configuration, of repositories, Maven plugin -->
<!-- configuration, and so. When starting with a small project, leave out the parent POM -->
<!-- reference. -->
<parent>
<groupId>com.x.y</groupId>
<artifactId>third-party-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- Better keep all project stuff together -->
<groupId>com.x.y.z</groupId>
<artifactId>your-project-name</artifactId>
<packaging>pom</packaging>
<name>My Little Sandbox</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<!-- Here only a reference to the compiled jar is required!!! -->
<!-- If a source jar is available, it will get pulled in automatically!!! -->
<!-- As this is done by (naming) convention of all jars, in a Maven repository -->
<dependency>
<groupId>com.x.y.thirdparty</groupId>
<artifactId>thirdparty</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
备注:新项目扩展第三方上级POM的罕见情况是新项目是第三方项目的某种扩展/插件。 然后,它可以使用与第3方相同的Maven插件版本,依赖项等。 令人欣喜的是,新的扩展/插件可与第三方软件的其他部分很好地配合使用。
尝试的具体例子
<?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>org.organisation.play-ground</groupId>
<artifactId>my-little-sandbox</artifactId>
<packaging>pom</packaging>
<name>My Little Sandbox</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<!-- A dependency reuired for each phase -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<!-- A dependency only needed during runtime phase -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>runtime</scope>
</dependency>
<!-- A dependency only needed during compile and test phase -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.