Skip to content

Commit 23bd0f4

Browse files
authored
Merge pull request #104242 from yucwan/patch-10
add gradle pivot to functions java quickstart
2 parents 9438578 + 68f6cc5 commit 23bd0f4

File tree

4 files changed

+106
-39
lines changed

4 files changed

+106
-39
lines changed

articles/azure-functions/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
href: functions-create-your-first-function-visual-studio.md
2323
- name: Command line
2424
href: functions-create-first-azure-function-azure-cli.md
25-
- name: Maven (Java)
25+
- name: Maven/Gradle (Java)
2626
href: functions-create-first-java-maven.md
2727
- name: Connect to storage
2828
items:
@@ -32,7 +32,7 @@
3232
href: functions-add-output-binding-storage-queue-vs.md
3333
- name: Command line
3434
href: functions-add-output-binding-storage-queue-cli.md
35-
- name: Maven (Java)
35+
- name: Maven/Gradle (Java)
3636
href: functions-add-output-binding-storage-queue-java.md
3737
- name: Tutorials
3838
items:

articles/azure-functions/functions-add-output-binding-storage-queue-java.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
---
22
title: Connect your Java function to Azure Storage
33
description: Learn how to connect an HTTP-triggered Java function to Azure Storage by using a Queue storage output binding.
4+
author: KarlErickson
5+
ms.author: karler
46
ms.date: 10/14/2019
57
ms.topic: quickstart
8+
zone_pivot_groups: java-build-tools-set
69
---
710

811
# Connect your Java function to Azure Storage
@@ -107,10 +110,19 @@ You're now ready to try out the new output binding locally.
107110

108111
As before, use the following command to build the project and start the Functions runtime locally:
109112

113+
::: zone pivot="java-build-tools-maven"
110114
```bash
111115
mvn clean package
112116
mvn azure-functions:run
113117
```
118+
::: zone-end
119+
120+
::: zone pivot="java-build-tools-gradle"
121+
```bash
122+
gradle jar --info
123+
gradle azureFunctionsRun
124+
```
125+
::: zone-end
114126

115127
> [!NOTE]
116128
> Because you enabled extension bundles in the host.json, the [Storage binding extension](functions-bindings-storage-blob.md#add-to-your-functions-app) was downloaded and installed for you during startup, along with the other Microsoft binding extensions.
@@ -133,9 +145,17 @@ Next, you use the Azure CLI to view the new queue and verify that a message was
133145

134146
To update your published app, run the following command again:
135147

136-
```azurecli
148+
::: zone pivot="java-build-tools-maven"
149+
```bash
137150
mvn azure-functions:deploy
138151
```
152+
::: zone-end
153+
154+
::: zone pivot="java-build-tools-gradle"
155+
```bash
156+
gradle azureFunctionsDeploy
157+
```
158+
::: zone-end
139159

140160
Again, you can use cURL to test the deployed function. As before, pass the value `AzureFunctions` in the body of the POST request to the URL, as in this example:
141161

@@ -157,4 +177,4 @@ Next, you should enable Application Insights monitoring for your function app:
157177
> [Enable Application Insights integration](functions-monitoring.md#manually-connect-an-app-insights-resource)
158178
159179

160-
[Azure Storage Explorer]: https://storageexplorer.com/
180+
[Azure Storage Explorer]: https://storageexplorer.com/

articles/azure-functions/functions-create-first-java-maven.md

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
---
2-
title: Use Java and Maven to publish a function to Azure
3-
description: Create and publish an HTTP-triggered function to Azure with Java and Maven.
4-
author: rloutlaw
2+
title: Use Java and Maven/Gradle to publish a function to Azure
3+
description: Create and publish an HTTP-triggered function to Azure with Java and Maven or Gradle.
4+
author: KarlErickson
5+
ms.author: karler
56
ms.topic: quickstart
67
ms.date: 08/10/2018
78
ms.custom: mvc, devcenter, seo-java-july2019, seo-java-august2019, seo-java-september2019
9+
zone_pivot_groups: java-build-tools-set
810
---
911

10-
# Quickstart: Use Java and Maven to create and publish a function to Azure
12+
# Quickstart: Use Java and Maven/Gradle to create and publish a function to Azure
1113

12-
This article shows you how to build and publish a Java function to Azure Functions with the Maven command-line tool. When you're done, your function code runs in Azure in a [serverless hosting plan](functions-scale.md#consumption-plan) and is triggered by an HTTP request.
14+
This article shows you how to build and publish a Java function to Azure Functions with the Maven/Gradle command-line tool. When you're done, your function code runs in Azure in a [serverless hosting plan](functions-scale.md#consumption-plan) and is triggered by an HTTP request.
1315

1416
<!--
1517
> [!NOTE]
@@ -21,44 +23,36 @@ This article shows you how to build and publish a Java function to Azure Functio
2123
To develop functions using Java, you must have the following installed:
2224

2325
- [Java Developer Kit](https://aka.ms/azure-jdks), version 8
24-
- [Apache Maven](https://maven.apache.org), version 3.0 or above
2526
- [Azure CLI]
2627
- [Azure Functions Core Tools](./functions-run-local.md#v2) version 2.6.666 or above
28+
::: zone pivot="java-build-tools-maven"
29+
- [Apache Maven](https://maven.apache.org), version 3.0 or above
30+
::: zone-end
31+
32+
::: zone pivot="java-build-tools-gradle"
33+
- [Gradle](https://gradle.org/), version 4.10 and above
34+
::: zone-end
2735

2836
You also need an active Azure subscription. [!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
2937

3038

3139
> [!IMPORTANT]
3240
> The JAVA_HOME environment variable must be set to the install location of the JDK to complete this quickstart.
3341
34-
## Generate a new Functions project
42+
## Prepare a Functions project
3543

44+
::: zone pivot="java-build-tools-maven"
3645
In an empty folder, run the following command to generate the Functions project from a [Maven archetype](https://maven.apache.org/guides/introduction/introduction-to-archetypes.html).
3746

38-
### Linux/macOS
39-
4047
```bash
41-
mvn archetype:generate \
42-
-DarchetypeGroupId=com.microsoft.azure \
43-
-DarchetypeArtifactId=azure-functions-archetype
48+
mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype
4449
```
4550

4651
> [!NOTE]
47-
> If you're experiencing issues with running the command, take a look at what `maven-archetype-plugin` version is used. Because you are running the command in an empty directory with no `.pom` file, it might be attempting to use a plugin of the older version from `~/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin` if you upgraded your Maven from an older version. If so, try deleting the `maven-archetype-plugin` directory and re-running the command.
52+
> If you're using Powershell, remeber to add "" around parameters.
4853
49-
### Windows
50-
51-
```powershell
52-
mvn archetype:generate `
53-
"-DarchetypeGroupId=com.microsoft.azure" `
54-
"-DarchetypeArtifactId=azure-functions-archetype"
55-
```
56-
57-
```cmd
58-
mvn archetype:generate ^
59-
"-DarchetypeGroupId=com.microsoft.azure" ^
60-
"-DarchetypeArtifactId=azure-functions-archetype"
61-
```
54+
> [!NOTE]
55+
> If you're experiencing issues with running the command, take a look at what `maven-archetype-plugin` version is used. Because you are running the command in an empty directory with no `.pom` file, it might be attempting to use a plugin of the older version from `~/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin` if you upgraded your Maven from an older version. If so, try deleting the `maven-archetype-plugin` directory and re-running the command.
6256
6357
Maven asks you for values needed to finish generating the project on deployment. Provide the following values when prompted:
6458

@@ -74,7 +68,35 @@ Maven asks you for values needed to finish generating the project on deployment.
7468

7569
Type `Y` or press Enter to confirm.
7670

77-
Maven creates the project files in a new folder with a name of _artifactId_, which in this example is `fabrikam-functions`.
71+
Maven creates the project files in a new folder with a name of _artifactId_, which in this example is `fabrikam-functions`. Run the following command to change the directory to the created project folder.
72+
```bash
73+
cd fabrikam-function
74+
```
75+
76+
::: zone-end
77+
::: zone pivot="java-build-tools-gradle"
78+
Use the following command to clone the sample project:
79+
80+
```bash
81+
git clone https://github.com/Azure-Samples/azure-functions-samples-java.git
82+
cd azure-functions-samples-java/
83+
```
84+
85+
Open `build.gradle` and change the `appName` in the following section to a unique name to avoid domain name conflict when deploying to Azure.
86+
87+
```gradle
88+
azurefunctions {
89+
resourceGroup = 'java-functions-group'
90+
appName = 'azure-functions-sample-demo'
91+
pricingTier = 'Consumption'
92+
region = 'westus'
93+
runtime {
94+
os = 'windows'
95+
}
96+
localDebug = "transport=dt_socket,server=y,suspend=n,address=5005"
97+
}
98+
```
99+
::: zone-end
78100

79101
Open the new Function.java file from the *src/main/java* path in a text editor and review the generated code. This code is an [HTTP triggered](functions-bindings-http-webhook.md) function that echoes the body of the request.
80102

@@ -83,15 +105,23 @@ Open the new Function.java file from the *src/main/java* path in a text editor a
83105
84106
## Run the function locally
85107

86-
Run the following command, which changes the directory to the newly created project folder, then builds and runs the function project:
108+
Run the following command to build then run the function project:
87109

88-
```console
89-
cd fabrikam-function
110+
::: zone pivot="java-build-tools-maven"
111+
```bash
90112
mvn clean package
91113
mvn azure-functions:run
92114
```
115+
::: zone-end
116+
117+
::: zone pivot="java-build-tools-gradle"
118+
```bash
119+
gradle jar --info
120+
gradle azureFunctionsRun
121+
```
122+
::: zone-end
93123

94-
You see output like the following from Azure Functions Core Tools when you run the project locally:
124+
You will see output like the following from Azure Functions Core Tools when you run the project locally:
95125

96126
```output
97127
...
@@ -107,7 +137,7 @@ Http Functions:
107137

108138
Trigger the function from the command line using cURL in a new terminal window:
109139

110-
```CMD
140+
```bash
111141
curl -w "\n" http://localhost:7071/api/HttpTrigger-Java --data AzureFunctions
112142
```
113143

@@ -130,13 +160,22 @@ az login
130160
> [!TIP]
131161
> If your account can access multiple subscriptions, use [az account set](/cli/azure/account#az-account-set) to set the default subscription for this session.
132162
133-
Use the following Maven command to deploy your project to a new function app.
163+
Use the following command to deploy your project to a new function app.
134164

135-
```console
165+
166+
::: zone pivot="java-build-tools-maven"
167+
```bash
136168
mvn azure-functions:deploy
137169
```
170+
::: zone-end
171+
172+
::: zone pivot="java-build-tools-gradle"
173+
```bash
174+
gradle azureFunctionsDeploy
175+
```
176+
::: zone-end
138177

139-
This `azure-functions:deploy` Maven target creates the following resources in Azure:
178+
This will create the following resources in Azure:
140179

141180
+ Resource group. Named with the _resourceGroup_ you supplied.
142181
+ Storage account. Required by Functions. The name is generated randomly based on Storage account name requirements.

articles/zone-pivot-groups.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ groups:
211211
title: JavaScript
212212
- id: programming-language-python
213213
title: Python
214+
- id: java-build-tools-set
215+
title: Build tools
216+
prompt: Choose a build tool
217+
pivots:
218+
- id: java-build-tools-maven
219+
title: Maven
220+
- id: java-build-tools-gradle
221+
title: Gradle
214222
- id: platforms-set-of-three
215223
title: Platforms
216224
prompt: Choose a platform

0 commit comments

Comments
 (0)