2

我正在尝试在 Windows 上使用 GraalVM 构建 JHipster 7 应用程序。我已经成功地让它与 macOS 和 Linux 一起工作。在 Windows 中,我收到有关命令行太长的错误。

[INFO] Executing: C:\Users\runneradmin\.graalvm\graalvm-ce-java17-22.0.0.2\bin\native-image.cmd -cp ...;D:\a\auth0-full-stack-java-example\auth0-full-stack-java-example\target\flickr-2-0.0.1-SNAPSHOT.jar --no-fallback --verbose -J-Xmx10g -H:Name=native-executable
The command line is too long.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

我已经复制并粘贴了 GitHub Actions 运行的命令,它的长度刚刚超过 12,000 个字符。根据该文档,Windows 仅支持 8191 个字符。

我尝试使用此建议缩短类路径,但没有帮助。我什至尝试过C:\r而不是C:\repo.

Twitter 上的人们建议使用 PowerShell 并将命令回显到文件中,然后运行该文件。但是,我还没有找到任何关于如何native-image.cmd从 Maven 中提取命令及其参数的示例。

你可以在这里找到我用来配置的 GitHub 操作。为了方便起见,我也将其粘贴在下面。

name: Publish

on:
  release:
    types: [published]

env:
  graalvm_version: '22.0.0.2'
  java_version: '17'
  branch: 'spring-native'

jobs:
  build:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
      with:
        ref: '${{ env.branch }}'
    - name: Set up GraalVM (Java ${{ env.java_version }})
      uses: graalvm/setup-graalvm@v1
      with:
        version: '${{ env.graalvm_version }}'
        java-version: '${{ env.java_version }}'
        components: 'native-image'

    - name: Cache Maven dependencies
      uses: actions/cache@v2
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-maven

    - name: Cache npm dependencies
      uses: actions/cache@v2
      with:
        path: |
          ~/.npm
          ~/.cache/Cypress/
        key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

    - name: Set up swap space
      if: runner.os == 'Linux'
      uses: pierotofy/set-swap-space@v1.0
      with:
        swap-size-gb: 10

    - name: Build native images
      run: ./mvnw -B -ntp package -Pnative,prod -DskipTests

    - name: Archive binary
      uses: actions/upload-artifact@v2
      with:
        name: flickr2-${{ matrix.os }}-x86_64
        path: target/native-executable

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
    - name: Rename binary
      run: mv target/native-executable target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64
    - name: Upload release
      uses: alexellis/upload-assets@0.3.0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        asset_paths: '["target/flickr2-${{ runner.os }}*"]'

  build-windows:
    name: GraalVM - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest]
    steps:
      - uses: actions/checkout@v2
        with:
          ref: '${{ env.branch }}'
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: microsoft/setup-msbuild@v1

      - name: Set up GraalVM (Java ${{ env.java_version }})
        uses: graalvm/setup-graalvm@v1
        with:
          version: '${{ env.graalvm_version }}'
          java-version: '${{ env.java_version }}'
          components: 'native-image'

      - name: Cache Maven dependencies
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-maven

      - name: Cache npm dependencies
        uses: actions/cache@v2
        with:
          path: |
            ~/.npm
            ~/.cache/Cypress/
          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

      - name: Configure pagefile
        uses: al-cheb/configure-pagefile-action@v1.2

      - name: Set up pagefile
        run: |
          (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
      - name: mvnw --version
        run: mvnw --version
        shell: cmd

      - name: Maven resolve
        run: mvnw -B -ntp dependency:resolve-plugins
        shell: cmd

      - name: Build native images
        run: |
          mklink /J C:\r C:\Users\runneradmin\.m2\repository
          mvnw -B -ntp package -Pnative,prod -DskipTests -Dmaven.repo.local=C:\r
        shell: cmd

      - name: Archive binary
        uses: actions/upload-artifact@v2
        with:
          name: flickr-${{ matrix.os }}-x86_64.exe
          path: target/native-executable.exe

      - name: Get release version
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

      - name: Rename binary
        run: move target/native-executable.exe target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64.exe
      - name: Upload release
        uses: alexellis/upload-assets@0.3.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          asset_paths: '["target/flickr2-${{ runner.os }}*"]'
4

1 回答 1

1

升级到 native-build-tools v0.9.10 可在 Windows 上修复此问题。更多详细信息,请访问https://github.com/graalvm/native-build-tools/issues/214https://github.com/graalvm/setup-graalvm/issues/6#issuecomment-1054582083

于 2022-03-01T02:03:19.753 回答