>我有一个父模块,有两个子模块(module1
和module2
)
module2
对module1
有一个 maven 依赖
在module2
中,我引用了一个module1
当我尝试跳转到此类的定义时,IntelliJ 在我的 maven 存储库中打开了.class文件。我希望它能在module1
跳到java类。如何让 IntelliJ 跳转此类文件?
我正在运行IntelliJ IDEA Ultimate 14.0.1
parent
绒球:
<?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>test</groupId>
<artifactId>test</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>module2</module>
<module>module1</module>
</modules>
</project>
module1
绒球:
<?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">
<parent>
<artifactId>test</artifactId>
<groupId>test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module1</artifactId>
</project>
module2
绒球:
<?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">
<parent>
<artifactId>test</artifactId>
<groupId>test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
stackoverflow的另一个答案帮助了我。 如果模块依赖项尚未到位,则基本上必须添加它们。
您有两个选择:
方式#1:
使用源构建module1
。这种方式可确保您始终拥有与使用的 Java 类一致的源代码。
要启用使用源代码构建,请将其添加到 maven 插件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
方式#2:
通过Project structure
> Modules
> Dependencies
> +
> 3. Module dependency
将您的module1
添加到module2
好吧,它不会像方式 #1 那样一致,但如果您使用的是 maven 构建,它的设置速度要快得多。如果您使用的是 intellij idea build,则可以将此依赖项标记为export
,以将其包含在module1
输出目录中。