Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.28.0

338 views Asked by At

Is something wrong with my pom.xml which could be causing GitHub actions to throw an error when trying to Restore Project Dependencies Using Mvn? I have a feeling there is some sort of compatibility issues with the versions being used but cannot tell.

Note: My application works perfectly fine locally. It is a basic application which leverages Java Azure Functions and CosmosDB to write and read data from a DB.

Error:

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>
1

There are 1 answers

0
Pravallika KV On

Follow below steps to deploy the Java CosmosDB triggered Azure function to Azure Function app using GitHub Actions.

  • I have created a CosmosDB triggered Azure function in Java.

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>

Local response:

enter image description here

  • Pushed the project to GitHub.

Steps to deploy the function using GitHub actions:

  • Create a Java Azure Function app in Azure Portal.
  • Go to Function app=> deployment=> Deployment Center, select GitHub as Source.
  • Sign into your GitHub account and select the repository and branch of your project.

enter image description here

  • It automatically creates a workflow under .github/workflows to deploy the function to Azure.

My Workflow:

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 }}

Deployment Status:

  • Able to deploy the function using GitHub actions:

enter image description here

enter image description here

Portal:

enter image description here