简体   繁体   English

Eclipse的Maven测试依赖关系

[英]Maven Test Dependencies with Eclipse

We are using Spring, Maven and Java in our project. 我们在项目中使用Spring,Maven和Java。 Sometimes we include dependencies to modules with scope "test". 有时,我们在范围“ test”中包括对模块的依赖。 So these are only availabe in test, not in production. 因此,这些仅在测试中可用,而不能在生产中使用。 Unfortunately eclipse is not that intelligent. 不幸的是,日食并不是那么聪明。 So when you use classes from those Test-Dependencies, you don't get compile errors. 因此,当您使用那些依赖于测试的类时,不会出现编译错误。 But when you later build it in some continuus integration environment via Maven (not compiling in eclipse) the correct workspace resolution gets used and it ends up with a compiler error. 但是,当您稍后通过Maven在某些连续集成环境中构建它(而不是在eclipse中编译)时,将使用正确的工作空间分辨率,并且最终会出现编译器错误。 Class Not Found... 找不到课程...

Does anyone have a solution for this? 有人对此有解决方案吗?

Maven using: you define in pom.xml. Maven使用:您在pom.xml中定义。 you put on with hand. 你戴上手。

how to do: 怎么做:

<!-- prod jar hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
        </dependency> 
<!-- testjar hibernate -->
        <dependency>
            <groupId>org.hibernate.test</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
        </dependency> 

you open to project path. 您打开项目路径。 you open window cmd with win+r short-key. 您用win + r快捷键打开cmd窗口。

mvn clean install -DskipTests 

(maven-3.5 add environment variables) if you see build success, nop. (maven-3.5添加环境变量),如果看到构建成功,请nop。

we adding .jar with dependency. 我们添加具有依赖项的.jar。 don't forget. 不要忘记 (test or really .jar) (测试或真的.jar)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM