簡體   English   中英

在沒有 mvn install:install-file 的情況下添加 maven 本地依賴項

[英]Adding maven local dependecies without mvn install:install-file

我的基本路徑下的文件夾 /src/main/resources/foobar 中有一些本地 jar 文件。

我將它們作為依賴項包含在我的 POM.xml 中:

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-models</artifactId>
    <version>1.5.4-SNAPSHOT</version>
</dependency>

現在我嘗試將它們添加到本地存儲庫:

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

現在我仍然收到錯誤消息,指出未找到此存儲庫中的 jars:

The following artifacts could not be resolved: bar... in file://.../repo was cached in the local repository, resolution will not be reattempted until the update interval of resource-repository has elapsed or updates are forced -> [Help 1]

我沒有使用過

mvn install:install-file

為此命令。 如果有我不需要這樣做的解決方案,我會很高興。

編輯:

文件夾結構為:

repo\io\swagger\swagger-models\1.5.4-SNAPSHOT

和 Jar 里面:

swagger-models-1.5.4-SNAPSHOT.Jar

有趣的是,我在運行 maven install 時收到有關此文件中缺少 POM 的警告。

您可以為第三方依賴項聲明一個存儲庫。

依賴項必須放在 repoBase 路徑中,jar 的目錄必須遵循以下模式:“{groupId}/{artifactId}/{artifactVersion}”。 在此文件夾中,jar 必須命名為“{artifactId}-{artifactVersion}.jar”。

例子:

<dependencies>
  <dependency>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

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


我的 pom 中有這個(當然還有 project-tag 和 group-id 等)
然后我在我的項目目錄中有一個目錄 repo。
在路徑“repo\\foo\\bar\\1.0”中,我在這個目錄中有一個“bar-1.0.jar”文件。 這為我編譯(好吧,jar 是空的,但這對於示例來說無關緊要)。
請注意,存儲庫的 url 不包含“file:”后的兩個斜杠。
我希望這個例子對於任何嘗試這樣做的人來說更容易理解。

我建議你在你的依賴標簽中使用系統標簽。 希望它會起作用。

暫無
暫無

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

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