-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure SDK Maven archetype for creating new projects (#25465)
* Azure SDK Maven archetype for creating new projects
- Loading branch information
Showing
14 changed files
with
380 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Release History | ||
|
||
## 1.0.0 (Unreleased) | ||
|
||
### Features Added | ||
- A dependency on the latest `azure-sdk-bom` BOM release, to ensure that all Azure SDK for Java dependencies are aligned | ||
and give you the best developer experience possible. | ||
- Built-in support for GraalVM native image compilation. | ||
- Support for generating a new project with a specified set of Azure SDK for Java client libraries. | ||
- Integration with the Azure SDK for Java build tooling that will give build-time analysis of your project to ensure | ||
as many best practices are followed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Azure SDK Maven Archetype | ||
|
||
The Azure SDK Maven archetype can accelerate the bootstrapping of a new project. The Azure SDK for Java Maven archetype | ||
creates a new application, with files and a directory structure that follows best practices. In particular, the | ||
Azure SDK for Java Maven archetype creates a new Maven project with the following features: | ||
|
||
* A dependency on the latest `azure-sdk-bom` BOM release, to ensure that all Azure SDK for Java dependencies are aligned and give you the best developer experience possible. | ||
* Built-in support for GraalVM native image compilation. | ||
* Support for generating a new project with a specified set of Azure SDK for Java client libraries. | ||
* Integration with the Azure SDK for Java build tooling that will give build-time analysis of your project to ensure as many best practices are followed. | ||
|
||
As the Azure SDK for Java Maven archetype is published to Maven Central, we can bootstrap a new application by using | ||
the archetype directly. | ||
|
||
```shell | ||
mvn archetype:generate \ | ||
-DarchetypeGroupId=com.azure.tools \ | ||
-DarchetypeArtifactId=azure-sdk-archetype | ||
``` | ||
|
||
After entering this command, a series of prompts will ask for details about your project so that the archetype can | ||
generate the right output for you. | ||
|
||
|
||
| Name | Description | | ||
|----------------|--------------| | ||
| groupId | (Required) Specifies the Maven groupId to use in the POM file created for the generated project. | | ||
| artifactId | (Required) Specifies the Maven artifactId to use in the POM file created for the generated project. | | ||
| package | (Optional) Specifies the package name to put the generated code into. If not specified, it is inferred from the groupId. | | ||
| azureLibraries | (Optional) A comma-separated list of Azure SDK for Java libraries, using their Maven artifact IDs. A list of such artifact IDs can be found [here](https://azure.github.io/azure-sdk/releases/latest/java.html). | | ||
| enableGraalVM | (Optional) By default GraalVM support will be enabled, but if `enableGraalVM` is set to false, the generated Maven POM file will not include support for compiling your application to a native image using GraalVM. | | ||
| javaVersion | (Optional) Specifies the minimum version of the JDK to target when building the generated project. By default it is the latest LTS release (currently Java 17), with valid ranges from Java 8 up. The value should just be the required Java version, for example, '8', '11', '17', etc. | | ||
| junitVersion | (Optional) The version of JUnit to include as a dependency. By default JUnit 5 will be used, but valid values are '4' and '5'. | | ||
|
||
If you would rather provide these values at the time of calling the archetype command above (for example, for | ||
automation purposes), you can specify them as parameters using the standard Maven syntax of appending `-D` to the | ||
parameter name, for example, `-DjavaVersion=17`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.azure.tools</groupId> | ||
<artifactId>azure-sdk-archetype</artifactId> | ||
<version>1.0.0</version> | ||
<name>Azure SDK Maven archetype</name> | ||
<description>Azure SDK archetype to generate a new Maven project with | ||
recommended Azure SDK tools and configuration.</description> | ||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<url>https://github.com/azure/azure-sdk-for-java</url> | ||
<organization> | ||
<name>Microsoft Corporation</name> | ||
<url>http://microsoft.com</url> | ||
</organization> | ||
|
||
|
||
<licenses> | ||
<license> | ||
<name>The MIT License (MIT)</name> | ||
<url>http://opensource.org/licenses/MIT</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>microsoft</id> | ||
<name>Microsoft Corporation</name> | ||
</developer> | ||
</developers> | ||
|
||
<issueManagement> | ||
<system>GitHub</system> | ||
<url>https://github.com/Azure/azure-sdk-for-java/issues</url> | ||
</issueManagement> | ||
|
||
<scm> | ||
<url>https://github.com/Azure/azure-sdk-for-java</url> | ||
<connection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</connection> | ||
<developerConnection/> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.archetype</groupId> | ||
<artifactId>archetype-packaging</artifactId> | ||
<version>3.2.0</version> <!-- {x-version-update;org.apache.maven.archetype:archetype-packaging;external_dependency} --> | ||
</extension> | ||
</extensions> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.archetype</groupId> | ||
<artifactId>maven-archetype-plugin</artifactId> | ||
<version>3.2.0</version> <!-- {x-version-update;org.apache.maven.archetype:maven-archetype-plugin;external_dependency} --> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/archetype-post-generate.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
dir = new File(new File(request.outputDirectory), request.artifactId) | ||
|
||
def run(String cmd) { | ||
def process = cmd.execute(null, dir) | ||
process.waitForProcessOutput((Appendable)System.out, System.err) | ||
if (process.exitValue() != 0) { | ||
throw new Exception("Command '$cmd' exited with code: ${process.exitValue()}") | ||
} | ||
} | ||
def mvnFileName = System.properties['os.name'].toLowerCase().contains('windows') ? 'mvn.cmd' : 'mvn' | ||
|
||
run("echo 'Updating to latest versions...'") | ||
run("$mvnFileName versions:update-properties -DincludeProperties=bom.version -DgenerateBackupPoms=false") |
31 changes: 31 additions & 0 deletions
31
sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<archetype-descriptor | ||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 https://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" | ||
name="azure-sdk-archetype"> | ||
<fileSets> | ||
<fileSet filtered="true" packaged="true"> | ||
<directory>src/main/java</directory> | ||
</fileSet> | ||
<fileSet filtered="true" packaged="true"> | ||
<directory>src/test/java</directory> | ||
</fileSet> | ||
</fileSets> | ||
|
||
<requiredProperties> | ||
<requiredProperty key="enableGraalVM"> | ||
<validationRegex>(true|false)</validationRegex> | ||
<defaultValue>true</defaultValue> | ||
</requiredProperty> | ||
<requiredProperty key="javaVersion"> | ||
<defaultValue>17</defaultValue> | ||
</requiredProperty> | ||
<requiredProperty key="junitVersion"> | ||
<validationRegex>(4|5)</validationRegex> | ||
<defaultValue>5</defaultValue> | ||
</requiredProperty> | ||
<requiredProperty key="azureLibraries"> | ||
</requiredProperty> | ||
</requiredProperties> | ||
|
||
|
||
</archetype-descriptor> |
142 changes: 142 additions & 0 deletions
142
sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<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>${groupId}</groupId> | ||
<artifactId>${artifactId}</artifactId> | ||
<version>${version}</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>${artifactId}</name> | ||
|
||
<properties> | ||
<maven.compiler.target>${javaVersion}</maven.compiler.target> | ||
<maven.compiler.source>${javaVersion}</maven.compiler.source> | ||
<bom.version>1.0.2</bom.version> | ||
<graalvm.version>21.2.0</graalvm.version> | ||
#if( ${junitVersion} == '4') | ||
<junit4.version>4.12</junit4.version> | ||
#end | ||
#if( ${junitVersion} == '5') | ||
<junit5.version>5.7.2</junit5.version> | ||
#end | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-sdk-bom</artifactId> | ||
<version>${bom.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
#set($libraries = ${azureLibraries}) | ||
#set($dependencies = $libraries.split(",")) | ||
#foreach($dependency in $dependencies) | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>$dependency.trim()</artifactId> | ||
</dependency> | ||
#end | ||
#if( ${enableGraalVM} == 'true') | ||
<dependency> | ||
<groupId>org.graalvm.sdk</groupId> | ||
<artifactId>graal-sdk</artifactId> | ||
<version>${graalvm.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
#end | ||
|
||
#if( ${junitVersion} == '4') | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit4.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
#end | ||
|
||
#if( ${junitVersion} == '5') | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
#end | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.azure.tools</groupId> | ||
<artifactId>azure-maven-plugin</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<configuration> | ||
<failOnMissingAzureSdkBom>true</failOnMissingAzureSdkBom> | ||
<failOnDeprecatedMicrosoftLibraryUsage>true</failOnDeprecatedMicrosoftLibraryUsage> | ||
<failOnUsingMicrosoftDependencyVersions>true</failOnUsingMicrosoftDependencyVersions> | ||
<failOnBeta>true</failOnBeta> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<configuration> | ||
<mainClass>${package}.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
#if( ${enableGraalVM} == 'true') | ||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.graalvm.nativeimage</groupId> | ||
<artifactId>native-image-maven-plugin</artifactId> | ||
<version>${graalvm.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>native-image</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<imageName>${artifactId}</imageName> | ||
<mainClass>${package}.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
#end | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/main/java/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ${package}; | ||
|
||
/** | ||
* A sample Azure application. | ||
*/ | ||
public class App { | ||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ols/azure-sdk-archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ${package}; | ||
|
||
#if( ${junitVersion} == 4 ) | ||
import org.junit.Test; | ||
#end | ||
|
||
#if( ${junitVersion} == 5) | ||
import org.junit.jupiter.api.Test; | ||
#end | ||
|
||
public class AppTest { | ||
|
||
@Test | ||
public void testApp() { | ||
// hello world | ||
} | ||
} |
Oops, something went wrong.