简体   繁体   English

Jenkins无法从本地存储库中找到Maven依赖项

[英]Jenkins cannot find maven dependency from local repository

I have added a jar file to my local maven repository by mvn install: install-file which works fine on my local machine. 我已经通过mvn install:install- file在我的本地Maven存储库中添加了一个jar文件,该文件在我的本地计算机上运行良好。 This is the dependency in my pom: 这是我pom中的依赖项:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>${oracle.connector.version}</version>
</dependency>

When running mvn clean install on my machine, everything works just fine. 在我的机器上运行mvn clean install时,一切正常。 Now I have a local jenkins instance running (on a Windows machine) which should build my project. 现在,我有一个运行在Windows机器上的本地jenkins实例,该实例应该可以构建我的项目。 The build runs into an error and jenkins says: 构建遇到错误,詹金斯说:

Could not find artifact com.oracle:ojdbc6:jar:11.2.0 in mirror1 (http://repo.maven.apache.org/maven2) -> [Help 1]

The project settings for jenkins looks like this: jenkins的项目设置如下所示: 在此处输入图片说明

<?xml version="1.0" encoding="UTF-8" ?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/
settings-1.0.0.xsd">
    <localRepository>${user.home}/.m2/repository</localRepository>
    <servers>
        <server>
            <id>nexusReleases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexusSnapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
    <mirrors>
    <mirror>
        <id>mirror1</id>
        <mirrorOf>*</mirrorOf>
        <name>Maven2 official repo</name>
        <url>http://repo.maven.apache.org/maven2</url>
    </mirror>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

And of course I've double checked the repository directory in .m2 . 当然,我已经仔细检查了.m2中的存储库目录。 The ojdbc6.jar is there. ojdbc6.jar在那里。

So what's wrong with my setup? 那么我的设置有什么问题呢?

You might want to check what Jenkins uses as its local repository. 您可能要检查Jenkins使用什么作为其本地存储库。

Go to Jenkins verwalten (Manage Jenkins) 前往Jenkins verwalten (管理Jenkins)

Under Maven-Projekt-Konfiguration (Maven project configuration), there should be a setting where the .m2 repository for Jenkins is located. Maven-Projekt-Konfiguration (Maven项目配置)下,应该存在一个设置,用于Jenkins的.m2存储库。

If that was not the same repository you were using locally, that would explain your error. 如果那不是您在本地使用的同一存储库,那将解释您的错误。

Edit: There is also an option for each job whether or not to use a "private repository". 编辑:每个作业还有一个选项,无论是否使用“专用存储库”。 That repository will be specific to that job and not share artifacts with any other. 该存储库将特定于该作业,并且不会与其他任何资源共享工件。

I had the same issue with ojdbc8.jar. 我对ojdbc8.jar有同样的问题。 The build failed with this dependency in my pom.xml. 由于我的pom.xml中存在此依赖性,构建失败。

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>19.3</version>
</dependency>

I copied the ojdbc8.jar to the Jenkins maven repository. 我将ojdbc8.jar复制到Jenkins Maven存储库。 After renaming it to ojdbc8-19.3.jar my build was successful. 将其重命名为ojdbc8-19.3.jar后,我的构建成功。

Perhaps this helps someone else. 也许这可以帮助其他人。

Use the following dependency: 使用以下依赖项:

<dependency>
    <groupId>com.oracle.ojdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>19.3.0.0</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM