| Branch | Status |
|---|---|
| Dev | |
| v3 |
Please refer to CONTRIBUTING.md for more information.
- Run all maven commands under the root folder of this repository
All Maven packages and plugins are restored from the upstream-public Azure Artifacts feed
(https://pkgs.dev.azure.com/azfunc/public/_packaging/upstream-public/maven/v1), which is configured
as the central repository in every pom.xml in this repository.
The repository root also has a settings.xml that mirrors central to the same
feed. It exists because a pom.xml cannot cover everything:
- Maven resolves build extensions and plugin prefixes before a pom's
<repositories>are honored, so those requests would otherwise go straight to Maven Central. MavenAuthenticate@0and the credential provider key credentials off the Azure Artifacts feed name (upstream-public), while the pom repository id must becentralin order to override the id Maven inherits from the Super POM. The mirror id bridges the two.
CI installs this file to ~/.m2/settings.xml. Locally you only need it when pulling a package or
version the feed has not cached yet, in which case pass it explicitly with mvn -s settings.xml.
The feed allows anonymous reads, so no credentials are required to build once a package version has
been saved to the feed. External contributors and fresh clones need no setup. mvn just works.
Never commit credentials or a <server> entry to settings.xml in this repository because doing so
would force authentication on everyone.
Authentication is only needed to ingest a package version that the feed has not cached yet. The first restore of any new or upgraded dependency will fail anonymously with:
No local versions of package '...'; please provide authentication to access versions from upstream that have not yet been saved to your feed.
When that happens, a Microsoft developer with access to the azfunc/public project must run the
restore once with credentials, which pulls the version from upstream and saves it to the feed. Every
subsequent anonymous restore then succeeds.
The recommended way to authenticate is the artifacts-maven-credprovider, which acquires a token via
Entra ID so you do not have to manage a PAT.
Run the helper script for your shell from the root of your clone. It installs the credential provider
into your local Maven repository if it is missing, then writes .mvn/extensions.xml. Both scripts
are idempotent, so re-running them is safe:
./eng/scripts/Install-MavenCredentialProvider.ps1./eng/scripts/install-maven-credprovider.shPass -Version / --version to install a different release, and -Force / --force to reinstall or
to overwrite an .mvn/extensions.xml the script does not manage.
If you would rather do it by hand, the equivalent steps are:
-
Bootstrap the credential provider once per machine. Run this from a directory outside any Maven project, such as your home directory. It downloads the extension from the public
AzureArtifactstools feed, which needs no authentication:mvn dependency:get "-Dartifact=com.microsoft.azure:artifacts-maven-credprovider:3.2.1" "-DremoteRepositories=central::::https://pkgs.dev.azure.com/artifacts-public/PublicTools/_packaging/AzureArtifacts/maven/v1"
Using the repository id
centralmatters. Maven records the extension as having come fromcentral, which is the same id this repository'spom.xmlfiles declare, so the cached copy validates during later builds. -
Create
.mvn/extensions.xmlat the root of your clone:<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.1.0 https://maven.apache.org/xsd/core-extensions-1.0.0.xsd"> <extension> <groupId>com.microsoft.azure</groupId> <artifactId>artifacts-maven-credprovider</artifactId> <version>3.2.1</version> </extension> </extensions>
.mvn/ is deliberately listed in .gitignore. Do not commit it. The extension exits when it
detects a build context, and committing it would break anonymous restores for everyone else.
If you would rather not use the credential provider, you can instead add a <server> entry to your
user-level ~/.m2/settings.xml (never to a file inside this repository), using an Azure DevOps
personal access token with Packaging read and write scope:
<settings>
<servers>
<server>
<!-- Must match the <id> of the repository declared in the pom.xml files. -->
<id>central</id>
<username>azfunc</username>
<password>[PERSONAL_ACCESS_TOKEN]</password>
</server>
</servers>
</settings>CI covers this automatically. The MavenAuthenticate@0 task in the build templates authenticates the
central repository, so merged changes to dependency versions are ingested by the pipeline. The
credential provider is not used in pipelines.
- Import the root folder of this repository as an existing project in IntelliJ
- Configure the Language level (under Project Structure -> Modules -> Sources) to 8
- Set workspace to the parent folder of this repository
- Import the root folder of this repository as an existing Maven project in Eclipse
- Configure the project Java compiler compliance level to 1.8
- Set the JRE libraries to JRE 1.8
- "Ignore optional compiler problems" in "Java Build Path" for "target/generated-sources/**/*.java"
This is a maven based project, thus you can use any command line tools or IDEs which support maven to build it. Here we will use command line as the example (you could configure your own development environment accordingly).
To build the project, you just need to run one command from the root folder of this project:
mvn clean packageAnd the binary will be built to "./azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar".
If you have updated the core interface (azure-functions-java-core), a mvn clean install is required for your test functions app to reference the latest core package.
- Update dependencies
mvn versions:use-latest-versions
- Update plugins
mvn versions:display-plugin-updates
For each of the plugin that displayed, update pom.xml
- Update version
mvn release:update-versions
The Java worker alone is not enough to establish the functions app, we also need the support from Azure Functions Host. You may either use a published host CLI or use the in-development host. But both of the methods require you to attach to the java process if you want a step-by-step debugging experience.
You can install the latest Azure functions CLI tool by:
npm install -g azure-functions-core-tools@coreBy default, the binaries are located in "<Home Folder>/.azurefunctions/bin". Copy the "<Azure Functions Java Worker Root>/azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar" to "<Home Folder>/.azurefunctions/bin/workers/java/azure-functions-java-worker.jar". And start it normally using:
func startA developer may also use the latest host code by cloning the git repository Azure Functions Host. Now you need to navigate to the root folder of the host project and build it through:
dotnet restore WebJobs.Script.sln
dotnet build WebJobs.Script.slnAfter the build succeeded, set the environment variable "AzureWebJobsScriptRoot" to the root folder path (the folder which contains the host.json) of your test functions app; and copy the "<Azure Functions Java Worker Root>/azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar" to "<Azure Functions Host Root>/src/WebJobs.Script.WebHost/bin/Debug/netcoreapp2.0/workers/java/azure-functions-java-worker.jar". Now it's time to start the host:
dotnet ./src/WebJobs.Script.WebHost/bin/Debug/netcoreapp2.0/Microsoft.Azure.WebJobs.Script.WebHost.dllNote: Remember to remove
"AzureWebJobsScriptRoot"environment variable after you have finished debugging, because it will also influence thefuncCLI tool.
Simply using the following command to do so (if there are dependency errors, run mvn clean install beforehand):
mvn javadoc:javadocJava worker now shades all its jars, to introduce any new jars it is required by the developers to add a section in the pom file to relocate it.
Our version strategy just follows the maven package version convention: <major>.<minor>.<hotfix>-<prerelease>, where:
<major>: Increasing when incompatible breaking changes happened<minor>: Increasing when new features added<hotfix>: Increasing when a hotfix is pushed<prerelease>: A string representing a pre-release version
Use SNAPSHOT pre-release tag for packages under development. Here is the sample workflow:
- Initially the package version is
1.0-SNAPSHOT. There is no hotfix for SNAPSHOT - Modify the version to
1.0.0-ALPHAfor internal testing purpose. Notice the hotfix exists here - After several BUG fixes, update the version to
1.0.0. - Create a new development version
1.1-SNAPSHOT. - Make a new hotfix into
1.0-SNAPSHOT, and release to version1.0.1. - New features are added to
1.1-SNAPSHOT.
Every time you release a non-development version (like 1.0.0-ALPHA or 1.0.1), you also need to update the tag in your git repository.
Primitives have two different type definitions, for example: int.class (which is identical to Integer.TYPE) is not Integer.class.
All Java types are represented by Type interface, which may be one of the following implementations:
Class<?>: normal class type likeStringParameterizedType: generic class type likeList<Integer>WildcardType: generic argument contains question mark like? extends NumberTypeVariable<?>: generic argument likeTGenericArrayType: generic array likeT[]
For the generic type behaviors (including compile-time validation and runtime type erasure) in Java, please refer to Generics in the Java Programming Language .
