如何让 travis-ci 从不同的 Maven 仓库下载 JAR 包?

huangapple go评论112阅读模式
英文:

How to make travis-ci download jars from a different maven repository?

问题

language: java
sudo: false
jdk:
  - openjdk8
scala: 2.12.7
cache:
  directories:
    - $HOME/.m2
branches:
  only:
    - master
script: mvn clean package

(Note: The provided content is the same as your .travis.yml file and does not require translation.)

英文:

my java/scala project is using maven as a build tool and I want to use travis-ci to test the build. The problem that I am facing is that my pom.xml has a third part repository set:

<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>
<groupId>org.sense.flink</groupId>
<artifactId>explore-flink</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>explore-flink</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<scala.binary.version>2.12</scala.binary.version>
<flink.version>1.11.1</flink.version>
<guava.version>29.0-jre</guava.version>
<junit.version>4.12</junit.version>
<scala.version>2.12.7</scala.version>
<geotools.version>21.2</geotools.version>
</properties>
<repositories>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-metrics-dropwizard</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-twitter_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-java-bridge_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-statebackend-rocksdb_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
<version>1.15</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.addthis</groupId>
<artifactId>stream-lib</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.geotools/ -->
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>${geotools.version}</version>
</dependency>
<!-- <dependency> <groupId>org.geotools</groupId> <artifactId>gt-epsg-hsql</artifactId> 
<version>${geotools.version}</version> </dependency> -->
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt</artifactId>
<version>${geotools.version}</version>
<!-- <scope>test</scope> -->
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geojsondatastore</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-metadata</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Make Scala available in project. Pay extra attention to the version -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>affinity</artifactId>
<version>3.1.11</version>
</dependency>
<dependency>
<groupId>io.airlift.tpch</groupId>
<artifactId>tpch</artifactId>
<version>0.10</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
</pluginManagement>
<finalName>explore-flink</finalName>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.10</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<!-- Run shade goal on package phase -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.flink:*</exclude>
<!-- Also exclude very big transitive dependencies of Flink WARNING: 
You have to remove these excludes if your code relies on other versions of 
these dependencies. -->
<exclude>org.slf4j:*</exclude>
<exclude>log4j:*</exclude>
<exclude>com.typesafe:config:*</exclude>
<exclude>junit:junit:*</exclude>
<exclude>com.codahale.metrics:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>org.apache.flink:*</artifact>
<excludes>
<!-- exclude shaded google but include shaded curator -->
<exclude>org/apache/flink/shaded/com/**</exclude>
<exclude>web-docs/**</exclude>
</excludes>
</filter>
<filter>
<!-- Do not copy the signatures in the META-INF folder. Otherwise, 
this might cause SecurityExceptions when using the JAR. -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!-- If you want to use ./bin/flink run <quickstart jar> uncomment 
the following lines. This will add a Main-Class entry to the manifest file -->
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.sense.flink.App</mainClass>
</transformer>
<!-- This bit merges the various GeoTools META-INF/services files -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

and when I build the project on travis-ci I get this error:

[WARNING] The POM for org.geotools:gt-referencing:jar:21.2 is missing, no dependency information available
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-epsg-wkt/21.2/gt-epsg-wkt-21.2.pom
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-epsg-wkt/21.2/gt-epsg-wkt-21.2.pom
[WARNING] The POM for org.geotools:gt-epsg-wkt:jar:21.2 is missing, no dependency information available
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-geojsondatastore/21.2/gt-geojsondatastore-21.2.pom
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-geojsondatastore/21.2/gt-geojsondatastore-21.2.pom
[WARNING] The POM for org.geotools:gt-geojsondatastore:jar:21.2 is missing, no dependency information available
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-metadata/21.2/gt-metadata-21.2.pom
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-metadata/21.2/gt-metadata-21.2.pom
[WARNING] The POM for org.geotools:gt-metadata:jar:21.2 is missing, no dependency information available
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-shapefile/21.2/gt-shapefile-21.2.pom
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-shapefile/21.2/gt-shapefile-21.2.pom
[WARNING] The POM for org.geotools:gt-shapefile:jar:21.2 is missing, no dependency information available
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-referencing/21.2/gt-referencing-21.2.jar
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-epsg-wkt/21.2/gt-epsg-wkt-21.2.jar
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-geojsondatastore/21.2/gt-geojsondatastore-21.2.jar
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-metadata/21.2/gt-metadata-21.2.jar
[INFO] Downloading from sonatype: https://oss.sonatype.org/content/repositories/releases/org/geotools/gt-shapefile/21.2/gt-shapefile-21.2.jar
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-referencing/21.2/gt-referencing-21.2.jar
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-epsg-wkt/21.2/gt-epsg-wkt-21.2.jar
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-geojsondatastore/21.2/gt-geojsondatastore-21.2.jar
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-metadata/21.2/gt-metadata-21.2.jar
[INFO] Downloading from sonatype-apache: https://repository.apache.org/content/repositories/releases/org/geotools/gt-shapefile/21.2/gt-shapefile-21.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.005 s
[INFO] Finished at: 2020-09-03T07:24:56Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project explore-flink: Could not resolve dependencies for project org.sense.flink:explore-flink:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: org.geotools:gt-referencing:jar:21.2, org.geotools:gt-epsg-wkt:jar:21.2, org.geotools:gt-geojsondatastore:jar:21.2, org.geotools:gt-metadata:jar:21.2, org.geotools:gt-shapefile:jar:21.2: Failure to find org.geotools:gt-referencing:jar:21.2 in https://maven-central.storage-download.googleapis.com/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of google-maven-central has elapsed or updates are forced -> [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/DependencyResolutionException
The command "eval mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V " failed. Retrying, 3 of 3.

I guess travis is downloading the sources from https://repository.apache.org/content/repositories/releases/org/geotools and I set on the pom.xml to download from http://download.osgeo.org/webdav/geotools/. How do I mage .travis.yml file download the jars from a different repository? This is my .travis.yml file:

language: java
sudo: false
jdk:
- openjdk8
scala: 2.12.7
cache:
directories:
- $HOME/.m2
branches:
only:
- master
script: mvn clean package

答案1

得分: 1

我遇到了同样的问题,我成功地通过在YAML文件中添加以下内容来绕过Travis CI,使用它自己的settings.xml文件。

before_install:
- mkdir -p $HOME/.m2
- cp my-settings.xml $HOME/.m2/settings.xml

这样,Travis CI执行的初始命令mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V将会使用my-settings.xml中指定的设置。

英文:

I ran into the same problem, I managed to bypass travis ci using it's own settings.xml by adding this to the YAML file.

 before_install:
- mkdir -p $HOME/.m2
- cp my-settings.xml $HOME/.m2/settings.xml

this way the initial mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V done by travis ci uses the settings specified in my-settings.xml.

huangapple
  • 本文由 发表于 2020年9月3日 15:54:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63719194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定