eclipse 构建成功但没有编译源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36171972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:05:51  来源:igfitidea点击:

Build is Success but No sources to compile

javaeclipsemavenselenium-webdriverpom.xml

提问by Ryan Martil

Maven test output in the Eclipse console:

Eclipse 控制台中的 Maven 测试输出:

[INFO] Scanning for projects...
    [WARNING] 
    [WARNING] Some problems were encountered while building the effective model for Mabi:Mabi:jar:0.0.1-SNAPSHOT
    [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.seleniumhq.selenium:selenium-java:jar -> duplicate declaration of version 2.45.0 @ line 20, column 21
    [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-surefire-plugin @ line 74, column 10
    [WARNING] 
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
    [WARNING] 
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
    [WARNING] 
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Mabi 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Mabi ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\com.TestCase
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.5:compile (default-compile) @ Mabi ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    [INFO] Compiling 166 source files to E:\workspace\Mabi\target\classes
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Mabi ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\test\resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.5:testCompile (default-testCompile) @ Mabi ---
    [INFO] No sources to compile
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ Mabi ---
    [INFO] No tests to run.
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7.287 s
    [INFO] Finished at: 2016-03-23T11:32:40+05:30
    [INFO] Final Memory: 21M/283M
    [INFO] ------------------------------------------------------------------------

Above image shows the directory of my project but when I run the project via Maven it gives me the above result without running the test. Looking forward for some accurate solutions.

上图显示了我的项目目录,但是当我通过 Maven 运行该项目时,它在没有运行测试的情况下给出了上述结果。期待一些准确的解决方案。

And this is what my POM.XML file looks like:

这就是我的 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>Mabi</groupId>
  <artifactId>Mabi</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.40.2</version>

    </dependency>             
        <dependency>              
            <groupId>org.seleniumhq.selenium</groupId>                              
            <artifactId>selenium-java</artifactId>                              
            <version>2.45.0</version>                               
        </dependency>                          
        <dependency>              
            <groupId>org.testng</groupId>                               
            <artifactId>testng</artifactId>                             
            <version>6.8</version>                                                                   
       </dependency>              
</dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>

    <resources>
      <resource>
        <directory>src/com.TestCase</directory>
        <includes>
        <include>**/com.*TestCase.java</include>
        </includes>
        </resource>    
     </resources>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5</version>
        <configuration>
          <source/>
          <target/>
        </configuration>
      </plugin>
     <plugin>


        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
                <inherited>true</inherited>
            <configuration>
                <suiteXmlFile>testng.xml</suiteXmlFile>
            </configuration>
    </plugin>
 </plugins>

</build>
</project>

回答by Shmulik Klein

Maven is all about "convention over configuration"idiom. In order that maven-surefire-pluginwill run your testcases it expects to find it under src/test/java, hence, you should follow the maven's standard directory layout and put all your test cases under src/test/java.

Maven 是关于“约定优于配置”的习语。为了maven-surefire-plugin运行您的测试用例,它希望src/test/javasrc/test/java.

enter image description here

在此处输入图片说明