java - Maven 将依赖项写入我的项目的根文件夹。我怎样才能解决这个问题?
问题描述
当我想打包我的 Java 源代码并运行mvn clean package
时,依赖项会从公共 maven 存储库中提取。但是,它们不是在本地.m2
存储库中结束,而是直接写入我项目的根文件夹。我该如何解决这个问题?
Pom.xml 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<artifactId>sample-docker-spark-job</artifactId>
<groupId>org.me.compute</groupId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<properties>
<main.class>org.me.compute.consumer.TwitterConnSparkConsumer</main.class>
<maven-shade-plugin.version>3.2.3</maven-shade-plugin.version>
<maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
<org.junit.jupiter.version>5.4.0</org.junit.jupiter.version>
<scala.binary.version>2.12</scala.binary.version>
<spark.dependency.scope>compile</spark.dependency.scope>
<spark.version>3.0.0</spark.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.dependency.scope}</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.dependency.scope}</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.dependency.scope}</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql-kafka-0-10_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.dependency.scope}</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${org.junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Run Junit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${org.junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- To generate an Uber Jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}</finalName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>module-info.class</exclude>
<exclude>scala/**</exclude>
<exclude>*.txt</exclude>
<exclude>*.properties</exclude>
<exclude>*.conf</exclude>
<exclude>scripts/*</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${main.class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- Pack JAR to a TAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>jar-to-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/tar.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
让我提一下,在我的 .m2 存储库中没有 settings.xml 文件。
此外,这是我在 IntelliJ IDEA 中的 maven 设置的屏幕截图:
我已经尝试删除我的本地存储库并从远程重新克隆,但这也没有帮助,尽管远程不包含预配置的.idea
文件夹或类似的东西,但只有源代码。之后我尝试使用不同的示例存储库并且问题是相同的,所以显然它必须链接到我的一般 maven 配置而不是存储库本身。我很感激任何建议!
解决方案
推荐阅读
- javascript - 如何使用递归转置 m*n 矩阵?
- git - 在 bitbucket/git 中,“xx commits behind proto. Sync Now”有什么作用?
- excel - 简单模式匹配宏中的 Excel-VBA 编译/语法错误
- javascript - 如何修复“位置 0 的 JSON 中的意外令牌 <”?
- android - 安迪模拟器上的查尔斯代理问题(失败:SSLHandshake:不支持的curveId:29)
- c - 语言 C、TCP 服务器和客户端
- python - ModuleNotFoundError:没有名为“scrapy_user_agents”的模块
- html - 想要使用 HTML 5 数据属性显示方法返回
- python - 如何使用 BeautifulSoup 抓取隐藏的数据元素
- css - flexbox 让内容消失