最近发现需要使用Maven的阴影插件来处理涉及Spark / Hadoop的依赖性地狱。
我的Scala应用程序目前有两个入口点:运行服务器的主服务和批处理作业类型类。我需要有两个超级罐子,每个罐子一个,放在${basedir}/target
文件夹中以及所有其他maven的东西,但它不起作用。我在下面指定的两个输出罐都以$ {basedir}结束,第三个以$ {basedir / target}结束。
我非常感谢任何有关此工作的建议。这是我的pom设置:
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.placeholder</groupId>
<artifactId>my-project</artifactId>
<description>my-project</description>
<version>0.75.0-SNAPSHOT</version>
<name>my-project</name>
<properties>
<!-- Properties removed -->
<version>1.23.4-SNAPSHOT</version>
</properties>
<dependencies>
<!-- Dependencies removed -->
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>service</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target</outputDirectory>
<outputFile>my-project-${project.version}.jar</outputFile>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.shaded.google</shadedPattern>
</relocation>
<relocation>
<pattern>com.ibm</pattern>
<shadedPattern>com.shaded.ibm</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.company.RunnableClassOne</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
<execution>
<id>snapshot</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target</outputDirectory>
<outputFile>my-project-other-runnable-${project.version}.jar</outputFile>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.shaded.google</shadedPattern>
</relocation>
<relocation>
<pattern>com.ibm</pattern>
<shadedPattern>com.shaded.ibm</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.company.RunnableClassTwo</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala.maven.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDir>${project.basedir}/src/main/scala</sourceDir>
<!-- to optimize generated bytecode -->
<compilerPlugins>
<compilerPlugin>
<groupId>com.nativelibs4java</groupId>
<artifactId>scalaxy-streams_2.11</artifactId>
<version>0.3.4</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
</plugin>
</plugins>
</build>
<!-- Distribution management and other things -->
提前致谢。