簡體   English   中英

maven中的兩個版本的依賴項

[英]two versions of dependencies in maven

有沒有辦法我可以通過命令開關來改變我的依賴關系?

意思是,我有

<dependency>
            <groupId>api</groupId>
            <artifactId>api</artifactId>
            <version>0.0.1-SNAPSHOT</version>

        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>

        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>

        </dependency>

並以這樣的方式設置它,如果我這樣做

mvn包-D提供

我有效的POM會

<dependency>
            <groupId>nmsc</groupId>
            <artifactId>nmsc_api</artifactId>
            <version>0.0.1-SNAPSHOT</version>

        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>provided</scope>
        </dependency>

不使用配置文件作為配置文件要求我將依賴項放入兩次。 這可能嗎?

如果將變量與變量配對,使用配置文件不需要多次列出依賴項,但如果您只是為單個屬性執行此操作,那么您可能只需直接覆蓋屬性:

<properties>
    <myExeScope>compile<myExeScope>
</properties>

<dependencies>
    <dependency>
        <groupId>nmsc</groupId>
        <artifactId>nmsc_api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <scope>${myExeScope}</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <scope>${myExeScope}</scope>
    </dependency>
</dependencies>

然后,您應該能夠覆蓋指定依賴項的范圍:

mvn -DmyExeScope=provided

注意,我沒有編譯這個,所以如果有拼寫錯誤請更正它們並注意更正。

暫無
暫無

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

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