编译引用已安装项目的项目

时间:2018-12-31 03:30:38

标签: maven intellij-idea

我有一个通过Maven创建的库模块,有console.log( "string name;" .replace(/string (\w+)/, "string $$$1") );个依赖项:

pom.xml

通过上述pom,我使用<?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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.18.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example.library</groupId> <artifactId>commons</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>commons</name> <description>common dependencies library</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 将其成功安装到了本地Maven存储库中。

在IntelliJ IDEA中使用该已安装库的另一个项目mvn install中,它可以很好地编译和运行。 my-service

中有pom.xml
my-service

但是,在与<?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"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-service</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>my-service</name> <description>My Services</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.18.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!-- other dependencies ... --> <dependency> <groupId>com.example.library</groupId> <artifactId>commons</artifactId> <version>1.0.0</version> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 一起运行时,出现以下错误:

mvn compile

库项目是作为IntelliJ IDEA模块的一部分与[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-service: Compilation failure: Compilation failure: [ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[3,45] package com.example.library.commons.filters does not exist [ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[17,13] cannot find symbol [ERROR] symbol: class SessionFilter [ERROR] location: class com.example.myservice.configs.WebSecurityConfig [ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[19,36] cannot find symbol [ERROR] symbol: class SessionFilter [ERROR] location: class com.example.myservice.configs.WebSecurityConfig 模块一起创建的。我猜IntelliJ IDEA知道如何在内部引用模块以编译依赖的模块,但是对于Maven,情况就不同了。

我的目标是将my-service模块编译和打包为包含my-service库模块的单个jar。现在我什至无法使用Maven进行编译,我做错了什么?

Apache Maven版本3.3.9。操作系统:OS X。

1 个答案:

答案 0 :(得分:0)

事实证明,库项目中不需要Spring-boot-maven插件,因为库不需要产生可执行的ueber jar。删除插件后,它将成功编译。