【问题标题】:How to use proxy with Tycho maven plugin?如何在 Tycho maven 插件中使用代理?
【发布时间】:2017-04-26 10:14:22
【问题描述】:

我正在尝试从公司防火墙后面构建 Eclipse Kura 项目。

当我尝试构建 kura/examples/org.eclipse.kura.example.camel.aggregation (mvn clean install) 时,它以:

结尾
Internal error: java.lang.RuntimeException: Failed to load p2 repository with ID 'eclipse.kura' from location http://packagedrone.eclipse.org/p2/eclipse-kura-2.1
(...)
Caused by: java.lang.RuntimeException: Failed to load p2 repository with ID 'eclipse.kura' from location http://packagedrone.eclipse.org/p2/eclipse-kura-2.1
    at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository(TargetPlatformFactoryImpl.java:296)
(...)
Caused by: java.net.SocketTimeoutException: Read timed out

我尝试设置代理:

               <plugin>
                        <groupId>org.eclipse.tycho</groupId>
                        <artifactId>tycho-maven-plugin</artifactId>
                        <version>${tycho-version}</version>
                        <extensions>true</extensions>
                        <configuration>
                                <argLine>-Dhttp.proxyHost=my-proxy-web -Dhttp.proxyPort=3128</argLine>
                        </configuration>
                </plugin>

但它没有用。 Kura 项目使用的是 v0.20.0 的 tycho-maven-plugin,我尝试升级到 1.0.0 但没有成功。

当我在浏览器中设置相同的代理时,我可以访问“http://packagedrone.eclipse.org/p2/eclipse-kura-2.1

更新: 我还已经在 maven settings.xml 中定义了我的代理,它可以在各种存储库中查找依赖项,但 Tycho maven 插件没有考虑到这一点:

  <proxies>
    <proxy>
      <id>main-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>my-proxy-web</host>
      <port>3128</port>
      <nonProxyHosts>*.mycomp.fr</nonProxyHosts>
    </proxy>
  </proxies>

更新 2:

使用 -X 和 -s settings.xml 运行时的 maven 调试日志:

[DEBUG] Clearing proxy settings in OSGi runtime

(这里只提到Tycho插件源对应的“proxy”,没有“Configuring proxy”也没有“Ignoring proxy”,好像没有找到“active”proxy)

[INFO] Computing target platform for MavenProject: org.eclipse.kura:org.eclipse.kura.example.camel.aggregation:1.1.0 @ /home/tristan/Dev/projects/IOT/kura.git/kura/examples/org.eclipse.kura.example.camel.aggregation/pom.xml
[DEBUG] Added p2 repository eclipse.kura (http://packagedrone.eclipse.org/p2/eclipse-kura-2.1)
[DEBUG] Using execution environment 'JavaSE-1.7' configured in Bundle-RequiredExecutionEnvironment
[DEBUG] Registered artifact repository org.eclipse.tycho.repository.registry.facade.RepositoryBlackboardKey(uri=file:/resolution-context-artifacts@/home/tristan/Dev/projects/IOT/kura.git/kura/examples/org.eclipse.kura.example.camel.aggregation)
[INFO] Adding repository http://packagedrone.eclipse.org/p2/eclipse-kura-2.1
[WARNING] Failed to access p2 repository http://packagedrone.eclipse.org/p2/eclipse-kura-2.1, use local cache.
org.eclipse.equinox.p2.core.ProvisionException: Unable to read repository at http://packagedrone.eclipse.org/p2/eclipse-kura-2.1/content.xml.
(...)
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to packagedrone.eclipse.org:80 timed out

更新 3: 我对“更新 2”的态度不好,我用太多的设置做了太多的测试,我为此测试使用了错误的文件。

这是正确设置代理的输出(仍然失败):

mvn clean install -X -s good-settings-with-proxy.xml

[DEBUG] Clearing proxy settings in OSGi runtime
[DEBUG] Configuring proxy for protocol http: host=10.91.31.45, port=3128

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.106
!MESSAGE System property http.proxyHost is not set but should be 10.91.31.45.

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.106
!MESSAGE System property http.proxyPort is not set but should be 3128.

如果我明确设置警告中询问的系统属性:

mvn clean install -X -Dhttp.proxyHost=10.91.31.45 -Dhttp.proxyPort=3128 -s /home/tristan/CODE/apache-maven-3.2.3/conf/settings.with-proxy.xml

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.079
!MESSAGE System property http.proxyHost has been set to 10.91.31.45 by an external source. This value will be overwritten using the values from the preferences

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.079
!MESSAGE System property http.proxyPort has been set to 3128 by an external source. This value will be overwritten using the values from the preferences
[DEBUG] Clearing proxy settings in OSGi runtime
[DEBUG] Configuring proxy for protocol http: host=10.91.31.45, port=3128, nonProxyHosts=*.edf.fr

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.106
!MESSAGE System property http.proxyHost is not set but should be 10.91.31.45.

!ENTRY org.eclipse.core.net 1 0 2017-04-28 18:02:58.106
!MESSAGE System property http.proxyPort is not set but should be 3128.

【问题讨论】:

  • 在您的 settings.xml 文件中定义代理...
  • 你可以猜到,它已经在那里定义了,它可以达到依赖关系,但不适用于 Tycho。
  • 您是否在 settings.xml 中正确定义了给定存储库 id 的代理?
  • 这是一个匿名代理,我没有任何登录名/密码来设置。您可以在“更新”部分看到我的 settings.xml 配置文件。

标签: maven maven-plugin tycho kura


【解决方案1】:

Tycho 从 settings.xml 派生配置,您需要在 Maven 的 settings.xml 中提供具有不同 ID 的 http 和 https 代理元素(以避免在 Tycho 配置文件中重叠)。

<proxies>
  <proxy>
    <id>123</id>
    <active>true</active>
    <protocol>https</protocol>
    <host>my-proxy-web</host>
    <port>3128</port>
    <nonProxyHosts>*.mycomp.fr</nonProxyHosts>
  </proxy>
  <proxy>
    <id>321</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>my-proxy-web</host>
    <port>3128</port>
    <nonProxyHosts>*.mycomp.fr</nonProxyHosts>
  </proxy>
</proxies>

【讨论】:

  • 使用 tycho 1.1.0 和 maven 3.5.4 为我工作
  • 就是这样,我在 settings.xml 中定义了一个 http 代理,但没有额外定义一个 https 代理。添加具有两个不同 id 的 https 有效!
【解决方案2】:

khmarbaise是对的,应该在maven的settings.xml中配置代理

maven 调试日志(mvn clean install -X)应该给你输出

https://github.com/eclipse/tycho/blob/f42e43c5722c0f74e55c5c03259476ac8b6f8836/tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/OSGiProxyConfigurator.java#L65

如果没有,您的代理设置由于某种原因没有被考虑

如需进一步调试 HTTP 客户端级别,请使用 apache HTTP 客户端跟踪,请参阅 https://wiki.eclipse.org/Equinox/p2/Reporting_Problems -> 报告网络连接问题

再次检查的另一个先决条件是,您的构建是否真的可以在没有代理和干净的本地 maven 存储库的情况下工作。

【讨论】:

  • 你是什么意思我“应该在 maven 的 settings.xml 中配置代理”,而不是我问题末尾显示的内容?我不明白你的第一句话,如果它与我写的设置相关,但我会尝试激活你在第谷源中找到的调试日志,这听起来很有用。
  • 添加了所有“代理”提及的调试跟踪。
  • 我在“更新 2”中犯了一个错误,好的输出在“更新 3”中(仍然失败)
  • 我建议如上所述打开 apache HTTP 客户端跟踪(或 tcpdump/wireshark)以检查线路上发生了什么
  • 这些是调试 Eclipse(也有 Tycho 插件)的选项,而不是 Maven。顺便说一句,eclipse 插件运行良好,只有 Maven 插件有 bug。我认为 Maven tycho 插件的行为仍然像在 Eclipse 中运行一样,有点像 tycho sunfire 插件:wiki.eclipse.org/Tycho/… 但如果我找不到任何与之相关的文档,我就扔掉这个废话。跨度>
猜你喜欢
  • 1970-01-01
  • 2015-02-26
  • 2015-03-07
  • 2023-03-23
  • 1970-01-01
  • 2018-10-03
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
相关资源
最近更新 更多