私は脂肪のJARに組み込むことをScalaのプロジェクトを持っています。今日、私はプロジェクトにいくつかのJavaクラスを追加する必要が、今、私のMavenのビルドが失敗しています。
このような私のプロジェクト構造のルックス(およそ):
.
├── src
│ └── main
│ ├── resources
│ │ └── Log4j.properties
| ├── java
│ │ └── com
│ │ └── myorg
│ │ └── myproject
│ │ └── MyPublicJavaClass.java
│ └── scala
│ └── com
│ └── myorg
│ └── myproject
│ └── spark
│ └── Main.scala
└── pom.xml
そして、ここに私のPOMファイルは次のようになります。
<?xml version="1.0"?>
<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>
<name>myproject</name>
<url>http://maven.apache.org</url>
<groupId>com.myorg</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>0.1.0-RELEASE</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.tools.version>2.11</scala.tools.version>
<scala.version>2.11.8</scala.version>
<spark.version>2.4.0</spark.version>
<aws.sdk.version>1.11.553</aws.sdk.version>
</properties>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<!-- I added this plugin today to try and make it compile the Java code -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- This compiles the Scala code -->
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This builds the fat JAR -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.myorg.myproject.spark.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.tools.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.tools.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazon.emr</groupId>
<artifactId>emr-dynamodb-hadoop</artifactId>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>com.github.scopt</groupId>
<artifactId>scopt_${scala.tools.version}</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-scala</artifactId>
<version>11.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
私は、Javaクラスを追加する前に、一緒にbuild-helper-maven-plugin
今日、Mavenは何の問題もなく、このプロジェクトをビルドすることができました。しかし、今、正しくプラグイン、または多分私は正しいものを使用していないことを私は設定していないようですか?
私のScalaのコードでは、型のオブジェクトを使用しようとしているMyPublicJavaClass
ので、今、私はこのようなMavenの表情で見ビルドエラーを:
[ERROR]〜/ srcに/メイン/スカラ座/ COM / MYORG / MyProjectと/火花/ Main.scala:227:エラー:見つかりません:タイプMyPublicJavaClassを
...
[ERROR]ゴールorg.scala-ツールの実行に失敗しました:Mavenの-スカーラ - プラグイン:2.15.2:プロジェクトmyprojectにコンパイル(デフォルト):ラップ:org.apache.commons.exec.ExecuteException:プロセスがエラーで終了しました:1 (終了値:1) - > [ヘルプ1]
私はと考えbuild-helper-maven-plugin
、コンパイル時前に生成するソースのリストにJavaコードのソースディレクトリを追加するには、それを言うだろうが、どうやらありません。私はこれをどのように修正することができますか?
あなたはScalaのコンパイルのために非常に古いプラグインを使用している(最後のバージョンが2.15.2
リリースされました2011年2月6日に)。
私のような、より最近のプラグインにアップグレードする最初のお勧めscala-maven-plugin
(最新のリリース4.0.2
2019年5月11日)。
その後、混合スカラ/ Javaソースとの例を見つけたことができますドキュメントで。使用する必要はありませんbuild-helper-maven-plugin
。この場合、また構成するにsourceDirectory
してはtestSourceDirectory
。この単純なを確認しpom.xml
、このプラグインを使用して(私はちょうど私がローカルで問題を再現するときに提供した例から未使用の依存関係を削除しました):
<?xml version="1.0"?>
<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>
<name>myproject</name>
<url>http://maven.apache.org</url>
<groupId>com.myorg</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>0.1.0-RELEASE</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.tools.version>2.11</scala.tools.version>
<scala.version>2.11.8</scala.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.0.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This builds the fat JAR -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.myorg.myproject.spark.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>