Подтвердить что ты не робот

Получение IntelliJ для импорта затененных зависимостей в многомодульном проекте maven

У меня есть два модуля: Component и Application. Модуль Component затенен из-за конфликта зависимостей (буферов протокола google) позже в процессе сборки.

<!-- snip from Component 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> 

Приложение зависит от модуля Component. Однако исходные файлы в приложении не могут ссылаться на затененную библиотеку, от которой зависит компонент. Это важно для взаимодействия с компонентом.

     <-- snip from Application pom.xml -->   
     <dependency>
          <groupId>my-group</groupId>
          <artifactId>component</artifactId>
          <version>${project.version}</version>
     </dependency>

Несмотря на то, что импорт не найден IntelliJ, сборка Maven отлично работает. Что я пропущу/делаю неправильно?

4b9b3361

Ответ 2

Я исправил аналогичную проблему, закрасив также исходный файл jar и распаковав его в исходный каталог:

<build>

    <sourceDirectory>${project.build.directory}/shaded-sources</sourceDirectory>

    <plugins>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <configuration>
          <skipSource>true</skipSource>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createSourcesJar>true</createSourcesJar>
              <shadeSourcesContent>true</shadeSourcesContent>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <artifactSet>
                <includes>
                  <include>com.google.guava:*</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>com.google.common</pattern>
                  <shadedPattern>org.apache.drill.shaded.com.google.common</shadedPattern>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.apache.drill.contrib</groupId>
                  <artifactId>guava-shaded</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <outputDirectory>${project.build.directory}/classes</outputDirectory>
                  <includes>**/**</includes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.drill.contrib</groupId>
                  <artifactId>guava-shaded</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <classifier>sources</classifier>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/shaded-sources</outputDirectory>
                  <includes>**/**</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
</build>

Ответ 3

build-helper-maven-plugin, кажется, добавляет затененную флягу в проект 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>

Для получения дополнительной информации см. Https://www.mojohaus.org/build-helper-maven-plugin/attach-artifact-mojo.html.

Ответ 4

Лучшим обходным решением кажется: щелкните правой кнопкой мыши на "компонент" проекта шарда → pom.xml в представлении проекта в IntelliJ, выберите "Maven" → "Игнорировать проекты". Затем выполните "Maven" → "Reimport" для проекта pom.xml.