Skip to content

Azure Functions Gradle Plugin

Andy Xu(devdiv) edited this page Apr 23, 2020 · 3 revisions

Azure Function Gradle Plugin is in Alpha stage, API may be changed or removed in stable releases.

How to use Gradle plugin for Azure Functions

Prerequisites

  • Gradle 4.10+
  • Latest Function Core Tools
  • Azure CLI. This plugin use Azure CLI for authentication, please make sure you have Azure CLI installed and logged in.
az login
az account set -s <your subscription id>

Step 1: prepare you azure function project

  mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype 

Follow https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven to create your azure function java project(maven)

Step 2: add build.gradle and settings.gradle to your azure function project

the content of build.gradle, remember to replace :

plugins {
  id "com.microsoft.azure.azurefunctions" version "1.0.1"
}
apply plugin: "java"

group 'com.fabrikam.functions'
version '1.0-SNAPSHOT'
 
dependencies {
  implementation 'com.microsoft.azure.functions:azure-functions-java-library:1.3.1'
  testCompile 'org.mockito:mockito-core:2.23.4'
  testCompile 'org.junit.jupiter:junit-jupiter-api:5.4.2'
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
}
 
azurefunctions {
    subscription = <your subscription ID>
    resourceGroup = 'java-functions-group'
    appName = 'fabrikam-functions-20191216104001380-01'
    pricingTier = 'Consumption'
    region = 'westus'
    runtime {
      os = 'windows'
    }
    appSettings {
        foo = 'bar'
    }

    authentication {
        type = 'azure_cli' 
    }
    localDebug = "transport=dt_socket,server=y,suspend=n,address=5005"
    deployment {
        type = 'run_from_blob'
    }
}

the content of settings.gradle:

rootProject.name = 'fabrikam-functions'

Step 3: run gradle jar --info

This step is to test whether your local env is ready.

Step 4: run gradle azureFunctionsPackage

This step is to prepare your staging folder (equals to mvn package).

Step 5: run gradle azureFunctionsRun

Test local run behavior like maven functions plugin(equals to mvn azure-functions:run)

Step 6: run gradle azureFunctionsDeploy

Test local deploy behavior like maven functions plugin(equals to mvn azure-functions:deploy)

Clone this wiki locally