1

我有一个带有两个子模块(module1module2)的父模块

module2有一个 Maven 依赖项module1

module2我引用了一个类module1

当我尝试跳转到此类的定义时,IntelliJ 在我的 maven 存储库中打开 .class 文件。我希望它跳转到 .java 中的 java 类module1。我怎样才能让 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>
4

2 回答 2

0

stackoverflow 上的另一个答案帮助了我。如果它们还没有到位,您基本上必须添加模块依赖项。

于 2016-03-30T12:42:41.027 回答
-1

你有两个选择:

方式#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:

通过> > > >添加您module1module2Project structureModulesDependencies+3. Module dependency

好吧,它不会像 #1 那样一致,但如果您使用的是 maven 构建,它的设置速度要快得多。如果您使用的是 intellij idea build,您可以将此依赖项标记为export将其包含在您的module1输出目录中。

于 2014-12-03T15:45:17.833 回答