首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译失败子包不存在

编译失败子包不存在
EN

Stack Overflow用户
提问于 2017-03-13 15:54:28
回答 1查看 1K关注 0票数 1

我正在尝试创建简单的Rest API应用程序,我想用jbehave框架检查它,一切都很好,直到我在我的service_tests项目中添加了对image_capture项目的依赖。

在我的代码中,一切都很好,我的service_tests可以识别image_capture类,但是当我尝试为父应用程序安装mvn时,我得到了

在项目service_tests上执行目标测试失败(默认- org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile )时出错:编译失败:编译失败:对于我的image_capture项目中的所有包。

我使用的是Rest API app的IntelliJ,java 8和spring boot。

我在stackoverflow中看到了很多答案,但其中一个没有成功。

提前感谢您的帮助。

我的父母pom:

代码语言:javascript
复制
        <modelVersion>4.0.0</modelVersion>
        <groupId>image_capture_parent</groupId>
        <artifactId>image_capture_parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>image_capture</module>
            <module>service_tests</module>
        </modules>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.1.RELEASE</version>
            <relativePath />
        </parent>
        <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

My first child project:

        <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>image_capture</artifactId>
    <packaging>jar</packaging>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-tomcat-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <portNames>
                                <portName>tomcat.http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>        

My second child project ( for running jbehave tests):

         <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>service_tests</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>image_capture_parent</groupId>
            <artifactId>image_capture</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jbehave/jbehave-maven-plugin -->
        <dependency>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-maven-plugin</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.5</version>
        </dependency>

    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>image_capture.com.Application</start-class>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <!-- Disable unit tests -->
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jbehave</groupId>
                <artifactId>jbehave-maven-plugin</artifactId>
                <version>3.8</version>
                <executions>
                    <execution>
                        <id>run-stories-as-embeddables</id>
                        <phase>integration-test</phase>
                        <configuration>
                            <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                            <ignoreFailureInStories>false</ignoreFailureInStories>
                            <ignoreFailureInView>false</ignoreFailureInView>
                        </configuration>
                        <goals>
                            <goal>run-stories-as-embeddables</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-30 17:19:35

我发现了一个原因:据我所知,Spring Boot类不能通过依赖项访问。这就是我的测试应用在通过Maven编译时看不到spring boot类的原因。解决方案是使用额外的应用程序,而不是spring boot应用程序,它具有表示spring boot实体类的类。

我在这篇文章中找到了一些参考:https://www.toptal.com/spring/top-10-most-common-spring-framework-mistakes

我在这里使用的解决方案是本文中的第2个常见错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42758749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档