Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

java - IntelliJ does not recognize generated classes added to the target/classes directory

I have a maven multi project. One of the modules has a dependency to a big library that was not properly packaged and is not configurable for use. Since we need this lib but only a couple of classes from it, we have decided to extract those classes and put them to the tartget/classes directory.

The project structure looks like:

PARENT
  - A (shared by B and C, needs some classes from a big library, which would need a lot heavy things like infrastructure aspects been configured that are not our stuff)
  - B (spring-boot-appilcation, depends on A)
  - C (spring-boot-appilcation, depends on A)

This approach works as a workaround, i.e. the spring-boot-applications can start and work properly but the IDEs are marking imports of the extracted classes as "not exist" despite, the classes were copied into target/classes.

We are using maven-dependency-plugin to extract the classes from the big library.

  <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.acme</groupId>
                  <artifactId>big-bad-library</artifactId>
                  <includes>
                    **/type/X.class,
                    **/type/Y.class
                  </includes>
                  <overWrite>false</overWrite>
                  <type>jar</type>
                  <version>${big.library.version}</version>
                </artifactItem>
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
              </artifactItems>
            </configuration>
            <goals>
              <goal>unpack</goal>
            </goals>
            <id>unpack</id>
            <phase>validate</phase>
          </execution>
        </executions>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.1.2</version>
  </plugin>         

IntelliJ won't find X and Y in the editor and will mark X and Y with e.g. "cannot resolve symbol X". Only adding the dependency com.acme:big-bad-library explicitly in the dependencies of A helps IntelliJ to "see/find" the classes and will solve this "cannot resolve symbol X" problem:

    <dependency>
      <groupId>com.daimler.daivb.vvr</groupId>
      <artifactId>virtual-vehicle-representation-api</artifactId>
      <version>${vvr.version}</version>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

But if this is the case, B and C cannot start because IntelliJ is including all the scrap from com.acme:big-bad-library, which was the initial problem we wanted to solve and avoid.

For B intelliJ will add the module A as a dependency. IntelliJ adds the module A as a dependency (e.g. see screenshot below "commons"-module). I suppose, it is taking A's pom.xml and providing com.acme:big-bad-library as well.

Module included as dependency

I have configured maven importing in intellij as shown below (Phase conf: generate-sources which runs after "validate", see maven-dependency-plugin above). For my understanding, IntelliJ should recognize the classes and there should be no need on having to add the com.acme:big-bad-library dependency in A's pom.xml to let the editor to work properly.

enter image description here

I need a hint on how I can configure IntelliJ or maven to:

  1. Let IntelliJ "see" the extracted classes in target/classes so it can check the classes exist so they won't get marked with "cannot resolve symbol X"
  2. Let IntelliJ "see" the extracted classes in target/classes of A in the other modules (B,C) too.
question from:https://stackoverflow.com/questions/65829337/intellij-does-not-recognize-generated-classes-added-to-the-target-classes-direct

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...