java 如何让Maven从本地仓库解析依赖项

yk9xbfzb  于 2023-08-01  发布在  Java
关注(0)|答案(1)|浏览(134)

我试图用Maven构建一个Java项目,但它无法从本地jar文件中找到工件。我正在尝试遵循here的指示。我尝试使用的库是由Maven打包的,具有groupIdgov.nasa.drf和artifactIdlib。
我的构建说明:

mvn clean
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=./repo/gov/nasa/drf/lib/lib-1.0.jar
mvn compile
mvn package

字符串
安装成功运行,但编译步骤失败,并显示

Failed to execute goal on project auth: Could not resolve dependencies for project gov.nasa.drf:auth:jar:2.0: Could not find artifact gov.nasa.drf:lib:jar:1.0 in data-local (file:///buildDir/repo)


为了部署(和一致性),我在Docker中运行构建命令。我的dockerfile:

FROM maven:3-openjdk-17 AS build

COPY ./src /buildDir/src
COPY ./repo /buildDir/repo
COPY pom.xml /buildDir/pom.xml
RUN mkdir ~/.m2

WORKDIR /buildDir
RUN mvn clean 
RUN mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=./repo/gov/nasa/drf/lib/lib-1.0.jar
RUN mvn compile 
RUN mvn package 

FROM openjdk:17-oracle
RUN mkdir -p /api/target
RUN mkdir -p /api/src/main
RUN mkdir /api/keys
RUN mkdir /api/logs
COPY src/main/resources /api/src/main/resources
COPY --from=build /buildDir/target /api/target
COPY pom.xml /api/pom.xml
WORKDIR /api
EXPOSE 8082
CMD ["java", "-jar", "/api/target/auth-2.0.jar"]


我的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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>gov.nasa.drf</groupId>
    <artifactId>auth</artifactId>
    <version>2.0</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <spring.version>6.1.0.RELEASE</spring.version>
        <aspectj.version>1.9.19</aspectj.version>
        <log4j2.version>2.17.1</log4j2.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.1</version>
    </parent>

    <repositories>
        <repository>
            <id>data-local</id>
            <name>data</name>
            <url>file://${project.basedir}/repo</url>
        </repository>
    </repositories>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>gov.nasa.drf.auth.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>3.1.2</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <parallel>both</parallel>
                    <threadCount>4</threadCount>
                    <includes>
                        <include>**/*Test</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.14.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outxml>true</outxml>
                    <verbose>true</verbose>
                    <showWeaveInfo>true</showWeaveInfo>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>gov.nasa.drf</groupId>
            <artifactId>lib</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.joschi.jackson</groupId>
            <artifactId>jackson-datatype-threetenbp</artifactId>
            <version>2.13.0-rc2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.28</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
    </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
    </dependencies>
</project>

cedebl8k

cedebl8k1#

对于install-file,您需要添加Maven坐标(GroupId、ArtifactId、Version)作为参数,以便将JAR放置在正确的位置。

相关问题