无法执行目标maven-antrun-plugin – 在GitHub Actions上连接超时

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

Failed to execute goal maven-antrun-plugin - Connection timed out on GitHub Actions

问题

以下是翻译好的内容:

我正在开发一个使用 Spring Boot + React/TypeScript 的应用程序,使用 GitHub Actions 进行持续集成和持续部署(CI/CD)。我最近添加了 react-app-rewired 包,以在不弹出 CRA 应用的情况下配置一些 webpack 设置。一切在本地构建和运行都很好(尽管速度稍慢),但是当推送到 GitHub 后,./mvnw test 命令在20多分钟后失败,并显示以下错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20:33 min
[INFO] Finished at: 2020-10-14T16:15:52Z
[INFO] ------------------------------------------------------------------------
Error:  Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project main: Execution default of goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run failed: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.8 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-antrun-plugin:jar:1.8 -> org.apache.maven:maven-plugin-api:jar:2.2.1: Failed to read artifact descriptor for org.apache.maven:maven-plugin-api:jar:2.2.1: Could not transfer artifact org.apache.maven:maven-plugin-api:pom:2.2.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom: Connection timed out (Read failed) -> [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/PluginResolutionException
Error: Process completed with exit code 1.

这是我们使用的 GitHub Actions 的 workflow.yml 文件:

name: Java CI/CD

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      JASYPT_ENCRYPTOR_PASSWORD: ${{secrets.JASYPT_ENCRYPTOR_PASSWORD}}
    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Build with Maven
      run: ./mvnw test

  deploy:
    needs: test
    if: github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    env:
      JASYPT_ENCRYPTOR_PASSWORD: ${{secrets.JASYPT_ENCRYPTOR_PASSWORD}}
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/heroku-deploy@v3.4.6
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "rocketden"
          heroku_email: "email@gmail.com"

这是我们的 pom.xml 文件:

<!-- 详细内容见原文 -->

这是我们的 package.json 文件:

<!-- 详细内容见原文 -->

如果需要进一步帮助或指导,将不胜感激。

英文:

I'm working on a Spring Boot + React/TypeScript app which uses GitHub Actions for CI/CD. I recently added the react-app-rewired package to configure some webpack settings without ejecting our CRA app. Everything builds and runs fine locally (albeit a bit slower), but when pushed to GitHub, the ./mvnw test command fails after 20+ minutes with the following error:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20:33 min
[INFO] Finished at: 2020-10-14T16:15:52Z
[INFO] ------------------------------------------------------------------------
Error:  Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project main: Execution default of goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run failed: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.8 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-antrun-plugin:jar:1.8 -&gt; org.apache.maven:maven-plugin-api:jar:2.2.1: Failed to read artifact descriptor for org.apache.maven:maven-plugin-api:jar:2.2.1: Could not transfer artifact org.apache.maven:maven-plugin-api:pom:2.2.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom: Connection timed out (Read failed) -&gt; [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/PluginResolutionException
Error: Process completed with exit code 1.

This is the GitHub Actions workflow.yml file we're using:

name: Java CI/CD

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      JASYPT_ENCRYPTOR_PASSWORD: ${{secrets.JASYPT_ENCRYPTOR_PASSWORD}}
    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Build with Maven
      run: ./mvnw test

  deploy:
    needs: test
    if: github.ref == &#39;refs/heads/master&#39;
    runs-on: ubuntu-latest
    env:
      JASYPT_ENCRYPTOR_PASSWORD: ${{secrets.JASYPT_ENCRYPTOR_PASSWORD}}
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/heroku-deploy@v3.4.6
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: &quot;rocketden&quot;
          heroku_email: &quot;email@gmail.com&quot;

Here is our pom.xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
    &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;groupId&gt;com.rocketden&lt;/groupId&gt;
  &lt;artifactId&gt;main&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;main&lt;/name&gt;
  &lt;description&gt;Our description&lt;/description&gt;

  &lt;properties&gt;
    &lt;java.version&gt;11&lt;/java.version&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;!-- WebSocket, STOMP, SockJS dependencies --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-websocket&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.webjars&lt;/groupId&gt;
      &lt;artifactId&gt;webjars-locator-core&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.webjars&lt;/groupId&gt;
      &lt;artifactId&gt;sockjs-client&lt;/artifactId&gt;
      &lt;version&gt;1.0.2&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.webjars&lt;/groupId&gt;
      &lt;artifactId&gt;stomp-websocket&lt;/artifactId&gt;
      &lt;version&gt;2.3.3&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.webjars&lt;/groupId&gt;
      &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
      &lt;version&gt;3.3.7&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.webjars&lt;/groupId&gt;
      &lt;artifactId&gt;jquery&lt;/artifactId&gt;
      &lt;version&gt;3.1.1-1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- Basic Spring framework dependencies --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
      &lt;exclusions&gt;
        &lt;exclusion&gt;
          &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
          &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
        &lt;/exclusion&gt;
      &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;!-- Enable ability to add Entity, Id, GeneratedValue tags --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
      &lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
      &lt;version&gt;2.2.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;!-- exclude tomcat jdbc connection pool, use HikariCP --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
      &lt;exclusions&gt;
        &lt;exclusion&gt;
          &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
          &lt;artifactId&gt;tomcat-jdbc&lt;/artifactId&gt;
        &lt;/exclusion&gt;
      &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;!-- MySQL database --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;!-- Lombok dependency to use Getters, Setters --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
      &lt;artifactId&gt;lombok&lt;/artifactId&gt;
      &lt;optional&gt;true&lt;/optional&gt;
    &lt;/dependency&gt;
    &lt;!-- Encryption for database configuration --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.github.ulisesbocchio&lt;/groupId&gt;
      &lt;artifactId&gt;jasypt-spring-boot-starter&lt;/artifactId&gt;
      &lt;version&gt;2.0.0&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- Logging dependency for testing --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j&lt;/artifactId&gt;
      &lt;version&gt;1.2.17&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- H2 database for testing --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.h2database&lt;/groupId&gt;
      &lt;artifactId&gt;h2&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;!-- Gson, convert Java objects to JSON --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
      &lt;artifactId&gt;gson&lt;/artifactId&gt;
      &lt;version&gt;2.8.6&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- Hikari Connection Pool --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.zaxxer&lt;/groupId&gt;
      &lt;artifactId&gt;HikariCP&lt;/artifactId&gt;
      &lt;version&gt;3.4.5&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- JUnit testing --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;4.13.1&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;!--  Model Mapper used to convert between DTOs and Entities  --&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.modelmapper&lt;/groupId&gt;
      &lt;artifactId&gt;modelmapper&lt;/artifactId&gt;
      &lt;version&gt;2.3.0&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;com.github.eirslett&lt;/groupId&gt;
        &lt;artifactId&gt;frontend-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;1.6&lt;/version&gt;
        &lt;configuration&gt;
          &lt;workingDirectory&gt;frontend&lt;/workingDirectory&gt;
          &lt;installDirectory&gt;target&lt;/installDirectory&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;install node and npm&lt;/id&gt;
            &lt;goals&gt;
              &lt;goal&gt;install-node-and-npm&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
              &lt;nodeVersion&gt;v14.8.0&lt;/nodeVersion&gt;
              &lt;npmVersion&gt;6.14.8&lt;/npmVersion&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
          &lt;execution&gt;
            &lt;id&gt;npm install&lt;/id&gt;
            &lt;goals&gt;
              &lt;goal&gt;npm&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
              &lt;arguments&gt;install&lt;/arguments&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
          &lt;execution&gt;
            &lt;id&gt;npm run build&lt;/id&gt;
            &lt;goals&gt;
              &lt;goal&gt;npm&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
              &lt;arguments&gt;run build&lt;/arguments&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
            &lt;configuration&gt;
              &lt;target&gt;
                &lt;copy todir=&quot;${project.build.directory}/classes/public&quot;&gt;
                  &lt;fileset dir=&quot;${project.basedir}/frontend/build&quot; /&gt;
                &lt;/copy&gt;
              &lt;/target&gt;
            &lt;/configuration&gt;
            &lt;goals&gt;
              &lt;goal&gt;run&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;

&lt;/project&gt;

And here is our package.json file:

{
  &quot;name&quot;: &quot;frontend&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;private&quot;: true,
  &quot;dependencies&quot;: {
    &quot;@stomp/stompjs&quot;: &quot;^5.4.4&quot;,
    &quot;@testing-library/jest-dom&quot;: &quot;^4.2.4&quot;,
    &quot;@testing-library/react&quot;: &quot;^9.3.2&quot;,
    &quot;@testing-library/user-event&quot;: &quot;^7.1.2&quot;,
    &quot;@types/jest&quot;: &quot;^24.0.0&quot;,
    &quot;@types/node&quot;: &quot;^12.0.0&quot;,
    &quot;@types/react&quot;: &quot;^16.9.0&quot;,
    &quot;@types/react-dom&quot;: &quot;^16.9.0&quot;,
    &quot;@types/react-router-dom&quot;: &quot;^5.1.5&quot;,
    &quot;@types/react-splitter-layout&quot;: &quot;^3.0.0&quot;,
    &quot;@types/sockjs-client&quot;: &quot;^1.1.1&quot;,
    &quot;@types/stompjs&quot;: &quot;^2.3.4&quot;,
    &quot;@types/styled-components&quot;: &quot;^5.1.2&quot;,
    &quot;axios&quot;: &quot;^0.20.0&quot;,
    &quot;react&quot;: &quot;^16.13.1&quot;,
    &quot;react-dom&quot;: &quot;^16.13.1&quot;,
    &quot;react-monaco-editor&quot;: &quot;^0.40.0&quot;,
    &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
    &quot;react-scripts&quot;: &quot;3.4.3&quot;,
    &quot;react-splitter-layout&quot;: &quot;^4.0.0&quot;,
    &quot;sockjs-client&quot;: &quot;^1.5.0&quot;,
    &quot;stompjs&quot;: &quot;^2.3.3&quot;,
    &quot;styled-components&quot;: &quot;^5.1.1&quot;,
    &quot;typeface-roboto&quot;: &quot;0.0.75&quot;,
    &quot;typescript&quot;: &quot;~3.7.2&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^2.34.0&quot;,
    &quot;@typescript-eslint/parser&quot;: &quot;^2.34.0&quot;,
    &quot;eslint&quot;: &quot;^6.8.0&quot;,
    &quot;eslint-config-airbnb&quot;: &quot;^18.2.0&quot;,
    &quot;eslint-plugin-import&quot;: &quot;^2.22.0&quot;,
    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.3.1&quot;,
    &quot;eslint-plugin-react&quot;: &quot;^7.20.6&quot;,
    &quot;eslint-plugin-react-hooks&quot;: &quot;^2.5.1&quot;
  },
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-scripts start&quot;,
    &quot;build&quot;: &quot;react-scripts build&quot;,
    &quot;test&quot;: &quot;react-scripts test&quot;,
    &quot;eject&quot;: &quot;react-scripts eject&quot;
  },
  &quot;proxy&quot;: &quot;http://localhost:8080&quot;,
  &quot;eslintConfig&quot;: {
    &quot;extends&quot;: &quot;react-app&quot;
  },
  &quot;browserslist&quot;: {
    &quot;production&quot;: [
      &quot;&gt;0.2%&quot;,
      &quot;not dead&quot;,
      &quot;not op_mini all&quot;
    ],
    &quot;development&quot;: [
      &quot;last 1 chrome version&quot;,
      &quot;last 1 firefox version&quot;,
      &quot;last 1 safari version&quot;
    ]
  }
}

Any help or guidance would be much appreciated.

答案1

得分: 1

对于下一个遇到这个问题的人 - 这基本上只是Azure SNAT和Maven交互的问题。Maven在内部池化连接,而Azure的SNAT以Java很难察觉的方式关闭这些连接,而且由于GitHub归Microsoft所有,GitHub Actions在Azure中运行。

无论如何 - 当前Maven版本的修复方法是设置一个Maven参数来降低连接池中的TTL。如果您需要使用较旧的版本,还有一些其他参数可以使用。

因此,我在工作流程中添加了一个环境变量:

MAVEN_OPTS: '-Dmaven.wagon.httpconnectionManager.ttlSeconds=120'

另请参阅:

英文:

For the next person who runs into this -- this is basically just an issue with Azure SNAT and Maven interacting. Maven internally pools connections and Azure's SNAT closes them in a way that Java kinda can't see, and Github Actions (since GitHub is owned by Microsoft) runs in Azure.

Anyway -- the fix with current Maven versions is to set a Maven parameter to dial down the TTL on the connection pool. If you need to use an older version, there are some other parameters you can use.

So I added an env var to my workflow:

MAVEN_OPTS: &#39;-Dmaven.wagon.httpconnectionManager.ttlSeconds=120&#39;

See also:

huangapple
  • 本文由 发表于 2020年10月15日 02:13:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64359222.html
匿名

发表评论

匿名网友

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

确定