Maven构建不生成类文件

时间:2018-11-23 11:07:34

标签: scala maven pom.xml

我正在尝试构建Maven项目,它不是在创建类文件,而是在生成一个jar文件。

我已经清理干净,然后安装然后打包。 下面是我的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>user.data.store</groupId>
  <artifactId>UserProcess</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <repositories>
    <repository>
      <id>cloudera</id>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.7</version>
   </dependency>

    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>1.2.0-cdh5.15.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-common</artifactId>
        <version>1.2.0-cdh5.15.1</version>
    </dependency>

  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.1.3</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <args>
                       <arg>-dependencyfile</arg>
                <arg>${project.build.directory}/.scala_dependencies</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.13</version>
        <configuration>
          <useFile>false</useFile>
          <disableXmlReport>true</disableXmlReport>
           <includes>
            <include>**/*Test.*</include>
            <include>**/*Suite.*</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>

  </build>
</project>

注意-我没有测试文件夹,虽然我的构建仍然成功,但是在Maven控制台中进入了以下位置:

        [INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for user.data.store:UserProcess:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.hbase:hbase-common:jar -> duplicate declaration of version 1.2.0-cdh5.15.1 @ line 172, column 17
[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 UserProcess 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-core_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-core_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 0.8 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-parent_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-parent_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (827 B at 1.3 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/com/cloudera/cdh/spark2-root/2.0.0.cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/com/cloudera/cdh/spark2-root/2.0.0.cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/com/cloudera/cdh/spark2-root/2.0.0.cloudera1-SNAPSHOT/maven-metadata.xml (607 B at 0.9 KB/sec)
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/com/cloudera/cdh/spark2-root/2.0.0.cloudera1-SNAPSHOT/maven-metadata.xml (607 B at 0.4 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-launcher_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-launcher_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-launcher_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-launcher_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-network-common_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-network-common_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-network-common_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-network-common_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-network-shuffle_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-network-shuffle_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-network-shuffle_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-network-shuffle_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-unsafe_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-unsafe_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-unsafe_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 1.7 KB/sec)
[INFO] Downloaded: https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/spark/spark-unsafe_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (2 KB at 1.7 KB/sec)
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ UserProcess ---
[INFO] Deleting E:\workspace\UserProcess\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ UserProcess ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\workspace\UserProcess\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ UserProcess ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- scala-maven-plugin:3.1.3:compile (default) @ UserProcess ---
[INFO] Downloading: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-parent_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded: https://repository.cloudera.com/artifactory/libs-snapshot-local/org/apache/spark/spark-parent_2.10/2.0.0-cloudera1-SNAPSHOT/maven-metadata.xml (827 B at 1.1 KB/sec)
[WARNING]  Expected all dependencies to require Scala version: 2.11.7
[WARNING]  user.data.store:UserProcess:0.0.1-SNAPSHOT requires scala version: 2.11.7
[WARNING]  org.scala-lang:scala-reflect:2.10.6 requires scala version: 2.10.6
[WARNING] Multiple versions of scala libraries detected!
[INFO] E:\workspace\UserProcess\src\main\scala:-1: info: compiling
[INFO] Compiling 3 source files to E:\workspace\UserProcess\target\classes at 1543295814300
[WARNING] warning: there were 5 deprecation warnings; re-run with -deprecation for details
[WARNING] one warning found
[INFO] prepare-compile in 0 s
[INFO] compile in 7 s
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ UserProcess ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\workspace\UserProcess\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ UserProcess ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scala-maven-plugin:3.1.3:testCompile (default) @ UserProcess ---
[WARNING]  Expected all dependencies to require Scala version: 2.11.7
[WARNING]  user.data.store:UserProcess:0.0.1-SNAPSHOT requires scala version: 2.11.7
[WARNING]  org.scala-lang:scala-reflect:2.10.6 requires scala version: 2.10.6
[WARNING] Multiple versions of scala libraries detected!
[WARNING] No source files found.
[INFO] 
[INFO] --- maven-surefire-plugin:2.13:test (default-test) @ UserProcess ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ UserProcess ---
[INFO] Building jar: E:\workspace\UserProcess\target\UserProcess-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ UserProcess ---
[INFO] Installing E:\workspace\UserProcess\target\UserProcess-0.0.1-SNAPSHOT.jar to C:\Users\kumar.harsh\.m2\repository\user\data\store\UserProcess\0.0.1-SNAPSHOT\UserProcess-0.0.1-SNAPSHOT.jar
[INFO] Installing E:\workspace\UserProcess\pom.xml to C:\Users\kumar.harsh\.m2\repository\user\data\store\UserProcess\0.0.1-SNAPSHOT\UserProcess-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.405 s
[INFO] Finished at: 2018-11-27T10:47:03+05:30
[INFO] Final Memory: 59M/738M
[INFO] ------------------------------------------------------------------------

我尝试手动删除目标文件夹,然后再次构建,但是再次遇到相同的情况。

我可以在目标/类文件夹中看到类文件

在运行scala代码时在控制台上进入下方:

Error: Could not find or load main class user.UserData

1 个答案:

答案 0 :(得分:0)

我认为您正在混淆。正如David Bernard所述,应该有一个target / classes文件夹,其中包含src/main/scala/

中的编译类。

现在要:

[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ UserProcess ---
[INFO] No sources to compile

这就是行家的工作方式。在不同的lifecycle phases中,有default plugins绑定到特定阶段。因此,现在当您进入test-compile阶段时,maven-compiler-plugin将被goal testCompile执行。