首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mvn deploy in Github actions提供401未授权

mvn deploy in Github actions提供401未授权
EN

Stack Overflow用户
提问于 2020-05-18 15:22:18
回答 1查看 1.8K关注 0票数 2

我曾多次尝试将工件从.github/workflows部署到https://maven.pkg.github.com,但都导致了401未经授权的错误。

代码语言:javascript
复制
      - name: Setup java for mvn deploy
        uses: actions/setup-java@v1
        with:
          java-version: 8

      - name: Deploy kaldi-linux.zip
        working-directory: kaldi
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          cp ../.github/kaldi/* .
          perl -pi -e 's/^(\s{4}<version>).*(<\/version>)/${1}$ENV{"KALDI_VERSION"}${2}/g' pom.xml
          mvn deploy
代码语言:javascript
复制
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy)
 on project kaldi: Failed to deploy artifacts: Could not transfer artifact org.kaldi:kaldi:pom:da93074
 from/to temp (https://maven.pkg.github.com/nalbion/vosk-api): Transfer failed for 
https://maven.pkg.github.com/nalbion/vosk-api/org/kaldi/kaldi/da93074/kaldi-da93074.pom 401 Unauthorized -> [Help 1]

日志地址:https://github.com/nalbion/vosk-api/runs/683615393?check_suite_focus=true

我的理解是,actions/setup-java应该提供settings.xml和环境变量,并且部署应该是直接的。是不是有什么我没做的事需要做?

EN

回答 1

Stack Overflow用户

发布于 2020-05-19 02:41:23

我可以通过第一手经验告诉你,将包部署到github的maven repos并非易事。忘记“包”部分中显示的“简单”步骤,这个过程比这复杂得多。然而,仍然有可能做到这一点。

对于初学者,您需要一个settings.xml文件。下面是我的最小设置:

代码语言:javascript
复制
<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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">

  <servers>
    <server>
      <id>github</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Authorization</name>
            <value>Bearer <GITHUB_TOKEN_GOES HERE></value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

我猜java操作会覆盖settings.xml,但上面的操作是必需的。另一种选择是使用用户名/密码方法,但这种方法很快就会过时,转而使用持有者令牌,就像我上面所做的那样。

现在,要部署一个带源代码的快照版本,我必须使用以下命令:

代码语言:javascript
复制
mvn clean source:jar deploy -DuniqueVersion=false -Dmaven.source.useDefaultManifestFile=true -Dmaven.source.includePom=true -Dmaven.install.skip=true -DdeplyAtEnd=true -DaltDeploymentRepository='github::default::https://maven.pkg.github.com/OWNER/REPOSITORY'

根据publishing guide,假设您的pom.xml中包含以下内容

代码语言:javascript
复制
<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

您可以将该命令更改为:

代码语言:javascript
复制
mvn clean source:jar deploy -DuniqueVersion=false -Dmaven.source.useDefaultManifestFile=true -DdeplyAtEnd=true -Dmaven.source.includePom=true -Dmaven.install.skip=true
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61864370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档