让IntelliJ在多模块maven项目中导入着色依赖项

And*_*ite 15 intellij-idea maven

我有两个模块,组件和应用程序.由于构建过程中稍后的依赖性冲突(谷歌协议缓冲区),组件模块被着色.

<!-- snip from Component's pom.xml -->
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-shade-plugin</artifactId>
     <version>2.3</version>
     <configuration>
         <relocations>
             <relocation>
                 <pattern>com.google.protobuf</pattern>                                
                 <shadedPattern>my.package.protocols.shaded.com.google.protobuf</shadedPattern>
             </relocation>
         </relocations>
     </configuration>
     <executions>
         <execution>
             <phase>package</phase>
             <goals>
                 <goal>shade</goal>
             </goals>
         </execution>
    </executions>
</plugin> 
Run Code Online (Sandbox Code Playgroud)

应用程序取决于组件模块.但是,Application中的源文件无法引用Component所依赖的着色库.这对于与Component进行交互至关重要.

     <-- snip from Application's pom.xml -->   
     <dependency>
          <groupId>my-group</groupId>
          <artifactId>component</artifactId>
          <version>${project.version}</version>
     </dependency>
Run Code Online (Sandbox Code Playgroud)

尽管IntelliJ无法找到导入,但Maven构建工作正常.我错过了什么/做错了什么?

Jan*_*yne 8

太糟糕了,在使用JetBrains打开机票后,此问题先前已报告过,目前在IntelliJ中不受支持.

  • 在第一张票中,最后一条评论给出了一个对我有用的很好的解决方法:更好的解决方法似乎是:在 IntelliJ 的项目视图中右键单击 shade-bug-repackaged -&gt; pom.xml,选择“Maven” - &gt;“忽略项目”。然后在顶级 pom.xml 上执行“Maven”-&gt;“重新导入”。 (2认同)

小智 5

build-helper-maven-plugin 似乎将阴影 jar 添加到 IntelliJ 项目中:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>compile</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>${basedir}/target/<YOUR JAR NAME>-SNAPSHOT.jar</file>
              <type>jar</type>
              <classifier>optional</classifier>
            </artifact>
          </artifacts> 
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅https://www.mojohaus.org/build-helper-maven-plugin/attach-artifact-mojo.html