Eclipse无法构建maven多模块项目

时间:2018-01-31 13:45:09

标签: java eclipse maven

我试图在Eclipse中构建一个多模块maven项目,但是,我在Eclipse Oxygen中获得了8670 Java Problems。我的项目有一个父项目,其pom.xml有以下部分声明子模块:

<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.neo4j</groupId>
<artifactId>graph-algorithms-parent</artifactId>
<version>3.3.2.0</version>
<packaging>pom</packaging>
<name>Neo4j Graph Algorithms</name>
<description>Efficient Graph Algorithms for Neo4j</description>

<profiles>
    <profile>
        <id>Benchmark</id>
        <modules>
            <module>benchmark</module>
        </modules>
    </profile>
</profiles>

<modules>
    <module>core</module>
    <module>algo</module>
    <module>tests</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <neo4j.version>3.3.1</neo4j.version>
    <jmh.version>1.19</jmh.version>
    <javac.target>1.8</javac.target>
</properties>

<organization>
    <name>Neo4j, Inc.</name>
    <url>https://neo4j.com</url>
</organization>

<developers>
    <developer>
        <id>neo-technology</id>
        <organization>Neo4j, Inc.</organization>
        <url>https://neo4j.com</url>
    </developer>
    <developer>
        <id>avgl</id>
        <organization>Avantgarde Labs GmbH</organization>
        <url>https://avantgarde-labs.de</url>
    </developer>
</developers>

<url>https://github.com/neo4j-contrib/neo4j-graph-algorithms</url>

<scm>
    <url>https://github.com/neo4j-contrib/neo4j-graph-algorithms</url>
</scm>

<licenses>
    <license>
        <name>GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007</name>
        <url>https://www.gnu.org/licenses/gpl.txt</url>
        <comments>
            Note that this license is for the project itself, and not for its dependencies.
            See the included NOTICE.txt file for further details.
        </comments>
        <distribution>repo</distribution>
    </license>
</licenses>


<dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>${neo4j.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-kernel</artifactId>
            <version>${neo4j.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-io</artifactId>
            <version>${neo4j.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.biville.florent</groupId>
            <artifactId>neo4j-sproc-compiler</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

        <!-- Benchmark Dependencies -->
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-core</artifactId>
            <version>${jmh.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-generator-annprocess</artifactId>
            <version>${jmh.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <!-- Neo4j Procedures require Java 8 -->
                <compilerVersion>${javac.target}</compilerVersion>
                <source>${javac.target}</source>
                <target>${javac.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
               <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
        </plugin>
       <plugin>
           <groupId>org.asciidoctor</groupId>
           <artifactId>asciidoctor-maven-plugin</artifactId>
           <version>1.5.3</version>
           <inherited>false</inherited>
           <executions>
               <execution>
                   <id>generate-docs</id>
                   <phase>package</phase>
                   <goals>
                       <goal>process-asciidoc</goal>
                   </goals>
               </execution>
           </executions>
           <configuration>
               <backend>html5</backend>
               <!--preserveDirectories>true</preserveDirectories -->
               <imagesDir>images</imagesDir>
               <sourceDirectory>${basedir}/doc</sourceDirectory>
               <sourceDocumentName>index.adoc</sourceDocumentName>
               <outputDirectory>${basedir}/target/docs</outputDirectory>
               <attributes>
                   <neo4j-version>${project.version}</neo4j-version>
               </attributes>
               <requires>
                   <require>asciidoctor-diagram</require>
               </requires>
               <source-highlighter>coderay</source-highlighter>
               <coderay-css>style</coderay-css>
           </configuration>
           <dependencies>
           <dependency>
               <groupId>org.asciidoctor</groupId>
               <artifactId>asciidoctorj-diagram</artifactId>
               <version>1.3.1</version>
           </dependency>
           </dependencies>
       </plugin>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <version>1.10.b1</version>
            <configuration>
                <header>gplv3-header.txt</header>
                <strictCheck>true</strictCheck>
                <failIfMissing>true</failIfMissing>
                <includes>
                    <include>**/*.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

然后我有4个子模块benchmarkcorealgotests和他们自己的pom.xml都正确引用了父项目(带有正确的版本号)。实际项目来自neo4j,您可以找到here

我尝试了maven clean install,项目成功构建没有任何问题。但是,当我将项目导入Eclipse时,我收到许多错误(主要来自父项目),其中包含... cannot be resolved to a type... cannot be resolved

我尝试过Maven - &gt; Update Project没有任何成功。我在Eclipse的Project Explorer视图中,所有5个项目处于同一级别。

我还尝试在Eclipse中添加Active Maven Profiles,但是没有解决问题。 My Embedded Maven版本为3.3.9 / 1.8.2.20171007-0216

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。问题是,我的Eclipse工作区是名为workspace的目录。但是,我的maven项目位于我创建的名为my_project的子文件夹中。当我克隆回购时,我cd进入my_project并做git clone

因此,我没有选择最高级workspace文件夹作为我的Eclipse工作区,而是选择了/workspace/my_project作为工作空间并解决了问题。