簡體   English   中英

maven-install-plugin 不加載本地依賴

[英]maven-install-plugin does not load local dependency

我正在嘗試使用 Maven maven-install-plugin 加載本地依賴項:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.5.2</version>
    <executions>
        <execution>
            <id>tetramap</id>
            <phase>initialize</phase>
            <goals>
                <goal>install-file</goal>
            </goals>
            <configuration>
                <groupId>tetramap</groupId>
                <artifactId>tetramap</artifactId>
                <version>1.0</version>
                <packaging>jar</packaging>
                <file>${project.basedir}/lib/tetraMap-1.0.jar</file>
            </configuration>
        </execution>
    </executions>
</plugin>
<dependency>
 <groupId>tetramap</groupId>
 <artifactId>tetraMap</artifactId>
 <version>1.0</version>
</dependency>

因此,下載的依賴項應該出現在存儲庫 (user/.m2/repository) 中。 這些文件應該出現在存儲庫中。 但是它們沒有上傳到存儲庫(“tetramap-1.0.jar”和“tetramap-1.0.pom”文件以及“maven-metadata-local.xm”文件丟失)。

請告訴我我做錯了什么。 我想在存儲庫 tetramap-1.0.jar、tetramap-1.0.pom 和 maven-metadata-local.xml 中查看上傳的文件。

更詳細:

我需要它來為使用 Vaadin 和 Spring 的項目創建一個 Docker 圖像。

我的 Dockerfile:

來自 openjdk:11-jdk-slim

COPY *.tetra ./
COPY src src
COPY frontend frontend
COPY route route
COPY package.json ./
COPY target/*.jar tetraweb.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/tetraweb.jar"]

如果 user/.m2/repository 目錄中沒有這樣的文件,那么當我運行命令時(創建一個 Docker 圖像):

sudo docker build . -t tetraweb:latest

然后我在容器中運行圖像


sudo docker run -p 8080:8080 tetraweb:latest

之后我得到一個錯誤:

java.lang.NoClassDefFoundError:

如果文件位於存儲庫 (user/.m2/repository) 目錄中,則 Docker 圖像會使用本地依賴項正確創建。

我嘗試以其他方式連接本地依賴項:

<dependency>
    <groupId>tetramap</groupId>
    <artifactId>tetraMap</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/tetraMap-1.0.jar</systemPath>
</dependency>

или

<repository>
    <id>local-repository</id>
    <url>file://${project.basedir}/lib</url>
</repository>

...

<dependency>
    <groupId>tetramap</groupId>
    <artifactId>tetraMap</artifactId>
    <version>1.0</version>
</dependency>

但結果到處都是一樣的:


java.lang.NoClassDefFoundError

我找到了一個臨時解決方案

我的 pom.xml:

<dependencies>
   <dependency>
            <groupId>tetramap</groupId>
            <artifactId>tetraMap</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/tetraMap-1.0.jar</systemPath>
   </dependency>
</dependencies>

...

<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <executions>
                <execution>
                    <id>inst_1</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <groupId>tetramap</groupId>
                        <artifactId>tetraMap</artifactId>
                        <version>1.0</version>
                        <packaging>jar</packaging>
                        <file>${project.basedir}/lib/tetraMap-1.0.jar</file>
                        <localRepositoryPath>/home/user/.m2/repository</localRepositoryPath>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

現在,如果我運行一個

mvn clean install

我在存儲庫中的目錄已正確填寫。 我看到下載的文件:

在此處輸入圖像描述

目前,創建 Docker 圖像仍然存在問題。 如果我運行命令:

mvn -Pproduction

我看到錯誤:

[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:23.2.7:build-frontend (default) on project tetraweb: Could not execute build-frontend goal: Error occured during goal execution: nullPlease run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace. NullPointerException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

但是如果我禁用以下代碼:

<!--            <scope>system</scope>
            <systemPath>${project.basedir}/lib/tetraMap-1.0.jar</systemPath>-->

我將再次運行命令:

mvn -Pproduction

這樣的話,鏡像創建就成功了

要將 jar 文件上傳到存儲庫,我需要包含的代碼:

<scope>system</scope>
                <systemPath>${project.basedir}/lib/tetraMap-1.0.jar</systemPath>

要創建 Docker 圖像,必須禁用此代碼:( 這很奇怪......

這是我的 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>
    <!-- Project from https://start.vaadin.com/project/553cf24a-aade-4a91-a94d-9f2293333d44 -->
    <groupId>oniip.tetra.web</groupId>
    <artifactId>tetraweb</artifactId>
    <name>tetraweb</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>11</java.version>
        <vaadin.version>23.2.7</vaadin.version>
        <!-- this parameter is needed as spring-boot bom overwrites it -->
        <selenium.version>4.5.3</selenium.version>
        <!-- selenium is so much verbose -->
        <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
    </properties>

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

    <repositories>
        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>vaadin-prereleases</id>
            <url>
                https://maven.vaadin.com/vaadin-prereleases/
            </url>
        </repository>
        <!-- Repository used by many Vaadin add-ons -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>vaadin-prereleases</id>
            <url>
                https://maven.vaadin.com/vaadin-prereleases/
            </url>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-testbench</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.31</version>
        </dependency>

        <!-- Include JUnit 4 support for TestBench and others -->
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.1.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.github.appreciated/apexcharts -->
        <dependency>
            <groupId>com.github.appreciated</groupId>
            <artifactId>apexcharts</artifactId>
            <version>23.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.11</artifactId>
            <version>2.4.20</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-remote_2.11</artifactId>
            <version>2.4.20</version>
        </dependency>

        <dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>

        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.55</version>
        </dependency>

        <dependency>
            <groupId>com.github.oshi</groupId>
            <artifactId>oshi-core</artifactId>
            <version>5.5.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.simplejavamail/simple-java-mail -->
        <dependency>
            <groupId>org.simplejavamail</groupId>
            <artifactId>simple-java-mail</artifactId>
            <version>5.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>com.github.bbottema</groupId>
            <artifactId>emailaddress-rfc2822</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.1</version>
        </dependency>

        <!-- Локальные репозитории -->
        <dependency>
            <groupId>org.jlibrtp</groupId>
            <artifactId>jlibrtp</artifactId>
            <version>1.0</version>
<!--            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jlibrtp.jar</systemPath>-->
        </dependency>
        <dependency>
            <groupId>org.snmp4j</groupId>
            <artifactId>snmp4j</artifactId>
            <version>1.11.3</version>
<!--            <scope>system</scope>
            <systemPath>${project.basedir}/lib/snmp4j-1.11.3.jar</systemPath>-->
        </dependency>
        <dependency>
            <groupId>tetra.commons</groupId>
            <artifactId>tetraCommons</artifactId>
            <version>1.0</version>
<!--            <scope>system</scope>
            <systemPath>${project.basedir}/lib/TetraCommons-1.0.jar</systemPath>-->
        </dependency>
        <dependency>
            <groupId>tetramap</groupId>
            <artifactId>tetraMap</artifactId>
            <version>1.0</version>
<!--            <scope>system</scope>
            <systemPath>${project.basedir}/lib/tetraMap-1.0.jar</systemPath>-->
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>spring-boot:run</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>inst_1</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>org.jlibrtp</groupId>
                            <artifactId>jlibrtp</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${project.basedir}/lib/jlibrtp.jar</file>
                            <localRepositoryPath>/home/user/.m2/repository</localRepositoryPath>
                        </configuration>
                    </execution>
                    <execution>
                        <id>inst_2</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>org.snmp4j</groupId>
                            <artifactId>snmp4j</artifactId>
                            <version>1.11.3</version>
                            <packaging>jar</packaging>
                            <file>${project.basedir}/lib/snmp4j-1.11.3.jar</file>
                            <localRepositoryPath>/home/user/.m2/repository</localRepositoryPath>
                        </configuration>
                    </execution>
                    <execution>
                        <id>inst_3</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>tetra.commons</groupId>
                            <artifactId>tetraCommons</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${project.basedir}/lib/TetraCommons-1.0.jar</file>
                            <localRepositoryPath>/home/user/.m2/repository</localRepositoryPath>
                        </configuration>
                    </execution>
                    <execution>
                        <id>inst_4</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>tetramap</groupId>
                            <artifactId>tetraMap</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${project.basedir}/lib/tetraMap-1.0.jar</file>
                            <localRepositoryPath>/home/user/.m2/repository</localRepositoryPath>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- Clean build and startup time for Vaadin apps sometimes may exceed
                     the default Spring Boot's 30sec timeout.  -->
                <configuration>
                    <jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5037</jvmArguments>
                    <wait>500</wait>
                    <maxAttempts>240</maxAttempts>
                </configuration>
            </plugin>

            <!--
                Take care of synchronizing java dependencies and imports in
                package.json and main.js files.
                It also creates webpack.config.js if not exists yet.
            -->
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-spring-boot</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-spring-boot</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Runs the integration tests (*IT) after the server is started -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <trimStackTrace>false</trimStackTrace>
                            <enableAssertions>true</enableAssertions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
</project>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM