簡體   English   中英

mvn包不會為具有編譯范圍的依賴項創建jar

[英]mvn package does not create jars for dependencies with compile scope

我來自Gradle,現在將我的一個項目切換到Maven。 Gradle自動為具有<scope>compile</scope>那些依賴項創建了jar,但看來Maven不會這樣做嗎? 有沒有辦法告訴Maven為我的作用域編譯依賴項創建jar?

這是我的pom.xml的一個片段,我希望為它在target文件夾中的某個位置創建jar

<dependencies>
    <dependency>
        <groupId>com.yubico</groupId>
        <artifactId>yubico-validation-client2</artifactId>
        <version>3.0.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.unboundid</groupId>
        <artifactId>unboundid-ldapsdk</artifactId>
        <version>4.0.8</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.9</version>
        <scope>compile</scope>
    </dependency>
<dependencies>

看起來沒有辦法像Gradle那樣優雅地處理此問題。 我必須使用maven-dependency-plugin手動導入依賴maven-dependency-plugin以便為啟動應用程序時發現的每個依賴項(即所有具有compile范圍maven-dependency-plugin創建jar。

因此,對於<dependency>作用域compile每個塊,我都必須在maven-dependency-plugin內使用<artifactItem> ,這是rollbar的示例:

<dependency>
    <groupId>com.rollbar</groupId>
    <artifactId>rollbar-java</artifactId>
    <version>1.4.0</version>
    <scope>compile</scope>
</dependency>

這對我有用:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
        <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <artifactItems>
            <artifactItem>
                <groupId>com.rollbar</groupId>
                <artifactId>rollbar-java</artifactId>
                <version>1.4.0</version>
                <type>jar</type>
            </artifactItem>
        </artifactItems>
    </configuration>
</plugin>

暫無
暫無

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

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