Intellij浏览多个maven项目 [英] Intellij navigate through multiple maven projects

查看:146
本文介绍了Intellij浏览多个maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个如下所示的文件结构:

  .git 
.project
.classpath
app1
pom.xml
.classpath
.project
src
app2
pom.xml
.classpath
.project
src
app3
pom.xml
.classpath
.project
src
TheAppIWorkOn
pom。 xml
.classpath
.project
src

TheAppIWorkOn使用jar来自app1,2和3的maven依赖,因此当我需要在app1,2或3中编辑某些东西时,这是一个痛苦的过程。如果我使用跳转到声明功能,它只会显示锁定的jar。有可能进行设置,以便当我跳转到声明时,它会转到我可以编辑的实际代码吗?

解决方案

如果你有一个 maven reactor build 它会为您完成所有模块设置。现在您只有jar文件的依赖项,而IntelliJ无法知道您有依赖的模块。但是你可以通过指出模块依赖关系帮助IntelliJ,然后你就可以在项目中的所有类之间导航。



最好的方法是创建项目根目录中的 pom.xml 。这个pom会将不同的模块保持在一起,并定义构建顺序。当你想第一次打开项目时,你只需将IntelliJ指向这个pom文件,所有的依赖关系都将被解析和设置,因此不同模块中的类之间的导航是轻而易举的。



根目录的示例pom文件:

 < 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.stackoverflow< / groupId>
< artifactId> Q16589702< / artifactId>
< packaging> pom< / packaging>
< version> 1.0-SNAPSHOT< / version>

< name> $ {project.artifactId} - $ {project.version}< / name>

< properties>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< / properties>

< modules>
< module> app1< / module>
< module> app2< / module>
< module> app3< / module>
< module> TheAppIWorkOn< / module>
< / modules>

< / project>

如果因某些原因无法执行此操作,则必须通知IntelliJ模块依赖项。您可以通过打开项目结构来完成此操作。





然后选择模块 TheAppIWorkOn 并按下底部的加号并选择模块依赖...





在那里你可以选择你想要的所有模块具有依赖性。





确定然后再次确定





现在你将成为能够在项目中的不同类之间导航。



如果 app1 app2 app3 彼此之间也有依赖关系你将不得不为他们做同样的事情。



但最简单的方法是在根项目目录中有一个pom文件,其中包含所有的模块间依赖关系。 / p>

So I have a file structure that looks like this:

.git
.project
.classpath
app1
    pom.xml
    .classpath
    .project
    src
app2
    pom.xml
    .classpath
    .project
    src
app3
    pom.xml
    .classpath
    .project
    src
TheAppIWorkOn
    pom.xml
    .classpath
    .project
    src

TheAppIWorkOn uses jars from app1, 2, and 3 which are maven dependencies so when I need to edit something in app1, 2, or 3 it's a painful process. If I use the "jump to declaration" functionality it just shows me the locked jar. Is it possible to set it up so that when I "Jump to declaration" it take me to the actual code that I can make edits on?

解决方案

If you would have a maven reactor build it would have made all the module setup for you. Now you only have dependencies to jar files and IntelliJ cannot know that you have the modules to depend on. But you can help IntelliJ by pointing out the module dependencies and after that you will be able to navigate between all the classes in the project.

The best way would be to create a pom.xml in the root directory of the project. This pom would keep together the different modules and also define the build order. When you want to open the project for the first time you just point IntelliJ to this pom file and all the dependencies would be resolved and setup so the navigation between classes in the different modules is a breeze.

Sample pom file for the root directory:

<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.stackoverflow</groupId>
    <artifactId>Q16589702</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>app1</module>
        <module>app2</module>
        <module>app3</module>
        <module>TheAppIWorkOn</module>
    </modules>

</project>

If you cannot do this for some reason then you'll have to inform IntelliJ about the module dependencies. You do this by opening up the Project Structure.

Then select the module TheAppIWorkOn and press the plus sign in the bottom and choose Module Dependency....

And there you can select all modules that you want to have as dependency.

Press Ok and then Ok again.

Now you will be able to navigate between the different classes in the project.

If app1, app2 and app3 also have dependencies between each other then you will have to do the same for them.

But the simplest way is definitely to have a pom file in the root project directory with all inter module dependencies there.

这篇关于Intellij浏览多个maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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