Грешка при компилиране на Maven поради липсващи генерирани класове

Преминах към нова настройка и сега командата mvn clean compile се проваля с това:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project OpenPatricianModel: Compilation failure: Compilation failure: 
[ERROR] /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java/ch/sahits/game/openpatrician/model/ship/impl/ShipWeaponsLocationFactory.java:[80,71] cannot find symbol
[ERROR]   symbol:   class WeaponLocation
[ERROR]   location: class ch.sahits.game.openpatrician.data.xmlmodel.weapon.WeaponLocations
[ERROR] /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java/ch/sahits/game/openpatrician/model/ship/impl/ShipWeaponsLocationFactory.java:[92,58] cannot find symbol
[ERROR]   symbol:   class WeaponLocation
[ERROR]   location: class ch.sahits.game.openpatrician.data.xmlmodel.weapon.WeaponLocations
[ERROR] /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java/ch/sahits/game/openpatrician/model/ModelConfiguration.java:[105,30] cannot find symbol
[ERROR]   symbol:   class Cities
[ERROR]   location: class ch.sahits.game.openpatrician.data.xmlmodel.map.Map
[ERROR] /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java/ch/sahits/game/openpatrician/model/city/impl/City.java:[151,71] cannot find symbol
[ERROR]   symbol:   class Cities
[ERROR]   location: class ch.sahits.game.openpatrician.data.xmlmodel.map.Map

От грешката става ясно, че не могат да бъдат намерени класове. Тези класове са генерирани по време на фазата generate-sources и след това са добавени към ресурсите с build-helper-maven-plugin. Следователно това изглежда различно от Защо Maven генерираните източници не се компилират?

Изпълнението на командата maven с -X показва, че изходната папка на генерираните java източници всъщност е на класовата пътека и файловете дори се откриват като остарели (защото са новосъздадени):

[DEBUG] Using compiler 'javac'.
[DEBUG] Adding /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated-sources/annotations to compile source roots:
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated/main/java
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated/src/main/java
[DEBUG] New compile source roots:
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/src/main/java
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated/main/java
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated/src/main/java
  /home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated-sources/annotations

Изглежда обаче, че тези източници не са компилирани.

Ето части от файла effictve pom:

  <plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <version>2.7.0</version>
    <executions>
      <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>xsdtojava</goal>
        </goals>
        <configuration>
          <xsdOptions>
            <xsdOption>
              <xsd>src/main/resources/map.xsd</xsd>
              <bindingFile>src/main/resources/jaxb-binding.xjb</bindingFile>
              <packagename>ch.sahits.game.openpatrician.data.xmlmodel.map</packagename>
            </xsdOption>
            <xsdOption>
              <xsd>src/main/resources/weaponLocation.xsd</xsd>
              <bindingFile>src/main/resources/jaxb-binding.xjb</bindingFile>
              <packagename>ch.sahits.game.openpatrician.data.xmlmodel.weapon</packagename>
            </xsdOption>
          </xsdOptions>
          <extensions>
            <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.7.0</extension>
          </extensions>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <extensions>
        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.7.0</extension>
      </extensions>
    </configuration>
  </plugin>

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <id>test</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>/home/andi/development/intellij/OpenPatrician/OpenPatricianModel/target/generated/main/java</source>
          </sources>
        </configuration>
      </execution>
      <execution>
        <id>add-test-source</id>
        <phase>process-resources</phase>
        <goals>
          <goal>add-test-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>src/it/java</source>
          </sources>
        </configuration>
      </execution>
      <execution>
        <id>add-test-resource</id>
        <phase>process-resources</phase>
        <goals>
          <goal>add-test-resource</goal>
        </goals>
        <configuration>
          <resources>
            <resource>
              <directory>src/it/resources</directory>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <executions>
      <execution>
        <id>default-compile</id>
        <phase>compile</phase>
        <goals>
          <goal>compile</goal>
        </goals>
        <configuration>
          <release>14</release>
          <source>13</source>
          <target>13</target>
        </configuration>
      </execution>
      <execution>
        <id>default-testCompile</id>
        <phase>test-compile</phase>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <release>14</release>
          <source>13</source>
          <target>13</target>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <release>14</release>
      <source>13</source>
      <target>13</target>
    </configuration>
  </plugin>

Проектът може да бъде компилиран от IDE (IntelliJ) и приложението се изпълнява.


person hotzst    schedule 17.07.2020    source източник
comment
надстроихте ли от по-ниска версия до java 11 или по-висока? След това ще трябва да погледнете вашите cxf добавки   -  person Paul    schedule 17.07.2020
comment
@Paul: Не, направих надстройката до Java 14 по-рано и тя работи. Единствената промяна, за която знам е, че сега използвам Maven 3.6.3, а преди беше 3.5.3 (мисля)   -  person hotzst    schedule 17.07.2020
comment
Вече не съм сигурен за версията на Maven, но имах нещо като същия проблем при надграждането. В крайна сметка трябваше да конфигурирам този плъгин, за да може Maven и Java-версията да са съвместими за генериране на ресурси: ‹groupId›org.codehaus.mojo‹/groupId› ‹artifactId›jaxb2-maven-plugin‹/artifactId› ‹version› 2.5.0‹/версия›   -  person Paul    schedule 17.07.2020