无法执行目标 com.microsoft.azure:azure-functions-maven-plugin:1.28.0

问题描述 投票:0回答:1

我的 pom.xml 是否有问题,可能导致 GitHub 操作在尝试使用 Mvn 恢复项目依赖项时抛出错误?我感觉正在使用的版本存在某种兼容性问题,但无法判断。

注意:我的应用程序在本地运行得很好。它是一个基本应用程序,利用 Java Azure Functions 和 CosmosDB 从数据库写入和读取数据。

错误:

Error:  Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.28.0:
        package (package-functions) on project azure-functions-java: Local Azure Functions Core Tools 
        does not exist or is too old to support function extension installation, skip package phase. 
        To install or update it, see: https://aka.ms/azfunc-install -> [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/MojoExecutionException
Error: Process completed with exit code 1.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>azure-functions-java</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>azure-functions-java</name>
    <description>Demo project for Azure Functions</description>
    <properties>
        <java.version>21</java.version>

        <functionResourceGroup>xxx-rg</functionResourceGroup>
        <functionAppServicePlanName>yyy</functionAppServicePlanName>
        <functionAppName>zzz</functionAppName>
        <functionAppRegion>westus</functionAppRegion>
        <functionPricingTier>Y1</functionPricingTier>

        <start-class>org.example.Main</start-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure.functions</groupId>
            <artifactId>azure-functions-java-library</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.10.1</version> 
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.microsoft.azure.functions</groupId>
                <artifactId>azure-functions-java-library</artifactId>
                <version>3.0.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source> 
                        <target>1.8</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>com.microsoft.azure</groupId>
                    <artifactId>azure-functions-maven-plugin</artifactId>
                    <version>1.28.0</version>

                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <configuration>
                    <resourceGroup>${functionResourceGroup}</resourceGroup>
                    <appName>${functionAppName}</appName>
                    <region>${functionAppRegion}</region>
                    <appServicePlanName>${functionAppServicePlanName}</appServicePlanName>
                    <pricingTier>${functionPricingTier}</pricingTier>

                    <hostJson>${project.basedir}/host.json</hostJson>
                    <localSettingsJson>${project.basedir}/local.settings.json</localSettingsJson>

                    <runtime>
                        <os>linux</os>
                        <javaVersion>21</javaVersion>
                    </runtime>
                    <appSettings>
                        <property>
                            <name>FUNCTIONS_EXTENSION_VERSION</name>
                            <value>~4</value>
                        </property>
                    </appSettings>
                </configuration>
                <executions>
                    <execution>
                        <id>package-functions</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
azure azure-functions azure-cosmosdb azure-java-sdk azure-functions-core-tools
1个回答
0
投票

按照以下步骤使用 GitHub ActionsJava CosmosDB 触发的 Azure 函数部署到 Azure Function 应用程序

  • 我在Java中创建了一个CosmosDB触发的Azure函数

pom.xml:

<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>com.example</groupId>
    <artifactId>azure-function-examples</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Azure Java Functions</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <azure.functions.maven.plugin.version>1.24.0</azure.functions.maven.plugin.version>
        <azure.functions.java.library.version>3.0.0</azure.functions.java.library.version>
        <functionAppName>azure-function-examples-1700545409673</functionAppName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure.functions</groupId>
            <artifactId>azure-functions-java-library</artifactId>
            <version>${azure.functions.java.library.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.23.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <version>${azure.functions.maven.plugin.version}</version>
                <configuration>
                    <appName>${functionAppName}</appName>
                    <resourceGroup>java-functions-group</resourceGroup>
                    <appServicePlanName>java-functions-app-service-plan</appServicePlanName>
                    <runtime>
                        <os>windows</os>
                        <javaVersion>8</javaVersion>
                    </runtime>
                    <appSettings>
                        <property>
                            <name>FUNCTIONS_EXTENSION_VERSION</name>
                            <value>~4</value>
                        </property>
                    </appSettings>
                </configuration>
                <executions>
                    <execution>
                        <id>package-functions</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>obj</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

当地回应:

enter image description here

  • 将项目推送到GitHub。

使用 GitHub actions 部署功能的步骤:

  • 在 Azure 门户中创建 Java Azure Function 应用程序。
  • 转到
    Function app=> deployment=> Deployment Center
    ,选择
    GitHub
    作为
    Source
  • 登录您的 GitHub 帐户并选择项目的存储库和分支。

enter image description here

  • 它会自动在
    .github/workflows
    下创建工作流程,以将函数部署到 Azure。

我的工作流程:

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_NAME: <function_app_name> # set this to your function app name on Azure
  PACKAGE_DIRECTORY: '.' # set this to the directory which contains pom.xml file
  JAVA_VERSION: '17' # set this to the java version to use

jobs:
  build-and-deploy:
    runs-on: windows-latest
    
    steps:
      - name: 'Checkout GitHub Action'
        uses: actions/checkout@v4

      - name: Setup Java Sdk ${{ env.JAVA_VERSION }}
        uses: actions/setup-java@v1
        with:
          java-version: ${{ env.JAVA_VERSION }}

      - name: 'Restore Project Dependencies Using Mvn'
        shell: pwsh
        run: |
          pushd './${{ env.PACKAGE_DIRECTORY }}'
          mvn clean package
          popd
      
      - name: 'Run Azure Functions Action'
        uses: Azure/functions-action@v1
        id: fa
        with:
          app-name: '<function_app_name>'
          slot-name: 'Production'
          package: '${{ env.PACKAGE_DIRECTORY }}'
          respect-pom-xml: true
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_E692B1861D6246058D40E4ADAADA7674 }}

部署状态:

  • 能够使用 GitHub actions 部署功能:

enter image description here

enter image description here

传送门:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.