【问题标题】:Maven build with jenkins for scala spark program : "No primary artifact to install, installing attached artifacts insteadMaven 使用 jenkins 构建 scala spark 程序:“没有要安装的主要工件,而是安装附加的工件
【发布时间】:2018-05-09 12:51:33
【问题描述】:

我有一个包含多个 scala spark 程序的项目,当我通过 eclipse 运行 mvn install 时,我能够生成正确的 jar,它与 spark-submit 命令一起运行。

将代码推送到 GIT 后,我们尝试使用 jenkins 构建它,因为我们希望使用 ansible 自动将 jar 文件推送到我们的 hadoop 集群。 我们有构建目标为“compile package install -X”的jenkinsfile。

日志显示-

[DEBUG](f)artifact = com.esi.rxhome:PROJECT1:jar:0.0.1-SNAPSHOT

[DEBUG](f) attachedArtifacts = [com.esi.rxhome:PROJECT1:jar:jar-   with-dependencies:0.0.1-SNAPSHOT, com.esi.rxhome:PROJECT1:jar:jar-with-dependencies:0.0.1-SNAPSHOT]

[DEBUG]   (f) createChecksum = false

[DEBUG]   (f) localRepository =       id: local
  url: file:///home/jenkins/.m2/repository/
layout: default
snapshots: [enabled => true, update => always]
releases: [enabled => true, update => always]

[DEBUG]   (f) packaging = jar

[DEBUG]   (f) pomFile = /opt/jenkins-data/workspace/ng_datahub-pipeline_develop-JYTJLDEXV65VZWDCZAXG5Y7SHBG2534GFEF3OF2WC4543G6ANZYA/pom.xml

[DEBUG]   (s) skip = false

[DEBUG]   (f) updateReleaseInfo = false

[DEBUG] -- end configuration --

[INFO] **No primary artifact to install, installing attached artifacts instead**

我在类似的帖子中看到了错误 -

Maven: No primary artifact to install, installing attached artifacts instead

但这里的答案是 - 删除自动清理,我不知道在詹金斯构建 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/maven-v4_0_0.xsd">
                <modelVersion>4.0.0</modelVersion>
                <groupId>com.esi.rxhome</groupId>
                <artifactId>PROJECT1</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <packaging>jar</packaging>
                <name>${project.artifactId}</name>
                <description>RxHomePreprocessing</description>
                <inceptionYear>2015</inceptionYear>
                <licenses>
                    <license>
                        <name>My License</name>
                        <url>http://....</url>
                        <distribution>repo</distribution>
                    </license>
                </licenses>

                <properties>
                    <maven.compiler.source>1.8</maven.compiler.source>
                    <maven.compiler.target>1.8</maven.compiler.target>
                    <encoding>UTF-8</encoding>
                    <scala.version>2.10.6</scala.version>
                    <scala.compat.version>2.10</scala.compat.version>
                </properties>

                <dependencies>
                    <dependency>
                        <groupId>org.scala-lang</groupId>
                        <artifactId>scala-library</artifactId>
                        <version>${scala.version}</version>
                    </dependency>

                    <!-- Test -->
                    <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.11</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.specs2</groupId>
                        <artifactId>specs2-core_${scala.compat.version}</artifactId>
                        <version>2.4.16</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.scalatest</groupId>
                        <artifactId>scalatest_${scala.compat.version}</artifactId>
                        <version>2.2.4</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.hive</groupId>
                        <artifactId>hive-jdbc</artifactId>
                        <version>1.2.1000.2.6.0.3-8</version>
                    </dependency>


                    <!-- <dependency>
                <groupId>org.apache.spark</groupId>
                <artifactId>spark-core_2.10</artifactId>
                <version>2.1.0</version>
            </dependency>

                    <dependency>
                <groupId>org.apache.spark</groupId>
                <artifactId>spark-sql_2.10</artifactId>
                <version>2.1.0</version>
            </dependency> -->


                    <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-core_2.10</artifactId>
                        <version>1.6.3</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-sql_2.10</artifactId>
                        <version>1.6.3</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-hive_2.10</artifactId>
                        <version>1.6.3</version>
                    </dependency>

                    <dependency>
                        <groupId>com.databricks</groupId>
                        <artifactId>spark-csv_2.10</artifactId>
                        <version>1.5.0</version>
                    </dependency>

                </dependencies>

                <build>
                    <sourceDirectory>src/main/scala</sourceDirectory>
                    <testSourceDirectory>src/test/scala</testSourceDirectory>
                    <plugins>
                        <plugin>
                            <!-- see http://davidb.github.com/scala-maven-plugin -->
                            <groupId>net.alchim31.maven</groupId>
                            <artifactId>scala-maven-plugin</artifactId>
                            <version>3.2.0</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>compile</goal>
                                        <goal>testCompile</goal>
                                    </goals>
                                    <configuration>
                                        <args>
                                            <arg>-make:transitive</arg>
                                            <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.18.1</version>
                            <configuration>
                                <useFile>false</useFile>
                                <disableXmlReport>true</disableXmlReport>
                                <!-- If you have classpath issue like NoDefClassError,... -->
                                <!-- useManifestOnlyJar>false</useManifestOnlyJar -->
                                <includes>
                                    <include>**/*Test.*</include>
                                    <include>**/*Suite.*</include>
                                </includes>
                            </configuration>
                        </plugin>
                        <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-jar-plugin</artifactId>
                                            <version>2.4</version>
                                          <configuration>
                                                <skipIfEmpty>true</skipIfEmpty>
                                                </configuration>
                                     <executions>
                                     <execution>
                              <goals>
                              <goal>jar</goal>
                        </goals>
                        </execution>
                        </executions>
                        </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-assembly-plugin</artifactId>
                            <version>3.0.0</version>
                            <configuration>
                                <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                                </descriptorRefs>
                                <archive>
                                  <manifest>
                                    <mainClass>com.esi.spark.storedprocedure.Test_jdbc_nospark</mainClass>
                                  </manifest>
                                </archive>
                            </configuration>
                            <executions>
                              <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                              </execution>
                            </executions>
                        </plugin>

                        <plugin>
                          <artifactId>maven-clean-plugin</artifactId>
                          <version>3.0.0</version>
                          <configuration>
                            <skip>true</skip>
                          </configuration>
                        </plugin>

                    </plugins>
                </build>
            </project>

我尝试指定

1 - "jar" 用于在 pom.xml 中打包。

2 - 将 maven 目标更改为 -

“安装”

“全新安装”

“编译包安装”

但上述尝试并没有帮助摆脱消息,并且创建的 jar 没有用。

当我尝试执行 spark 提交命令时-

            spark-submit  --driver-java-options -Djava.io.tmpdir=/home/EH2524/tmp --conf spark.local.dir=/home/EH2524/tmp --driver-memory 2G --executor-memory 2G --total-executor-cores 1 --num-executors 10 --executor-cores 10 --class com.esi.spark.storedprocedure.Test_jdbc_nospark  --master yarn  /home/EH2524/PROJECT1-0.0.1-20171124.213717-1-jar-with-dependencies.jar
            Multiple versions of Spark are installed but SPARK_MAJOR_VERSION is not set
            Spark1 will be picked by default
            java.lang.ClassNotFoundException: com.esi.spark.storedprocedure.Test_jdbc_nospark
                    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
                    at java.lang.Class.forName0(Native Method)
                    at java.lang.Class.forName(Class.java:348)
                    at org.apache.spark.util.Utils$.classForName(Utils.scala:175)
                    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:703)
                    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
                    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
                    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
                    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

这里,Test_jdbc_nospark 是一个 scala 对象。

【问题讨论】:

    标签: scala maven apache-spark jenkins jenkins-pipeline


    【解决方案1】:

    此消息是因为 maven-jar-plugin 具有 as true。一旦我删除它,构建不会给出消息“没有要安装的主要工件,而是安装附加的工件”

    由于 pom.xml 中的路径不正确,正在创建空 jar

    最初-

        <build>
          <sourceDirectory>src/main/scala</sourceDirectory>
    

    由于 jenkins 正在通过 git 中的代码进行构建,并且 pom 位于项目文件夹中。

    <build>
        <sourceDirectory>folder_name_in_git/src/main/scala</sourceDirectory>
    

    【讨论】:

      【解决方案2】:

      我不确定,但您的 maven-jar-plugin 配置看起来很可疑。通常,执行会指定一个阶段,如

        <execution>
          <phase>package</phase>
          <goals>
            <goal>jar</goal>
          </goals>
      

      (来自this example)。也许忽略这会导致您的默认 jar 无法构建?当然,错误消息听起来像是您的默认 jar 没有被构建,但您实际上并没有这么说。

      【讨论】:

      • 此消息是因为 maven-jar-plugin 将 设为 true。一旦我删除了这个,构建不会给出消息“没有要安装的主要工件,而是安装附加的工件”但是这里的另一个问题是创建的 jar(主要工件)没有所需的 scala 对象,因此我不能运行 scala spark 程序。创建的 jar 大小仅为 3kb,也只是为了在我在 eclipse 中运行 maven install 时提供更多信息,创建的 jar 是正确的,我能够运行 scala spark 程序。
      • 进一步挖掘,我看到 Jenkins 正在打印消息,No source to compile 这会导致创建一个空 jar。 ? ([INFO] --- maven-compiler-plugin:3.1:compile (default-compile ) @ PROJECT1 --- [INFO] No sources to compile?) 试图了解为什么它无法获取源代码进行编译。 @乔
      • 无法在 Eclipse 前端提供帮助(我使用 IntelliJ),但听起来您的 Eclipse 项目不知何故未使用 Maven 使用的默认配置。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多