Skip to content

Commit

Permalink
Azure SDK Maven archetype for creating new projects (#25465)
Browse files Browse the repository at this point in the history
* Azure SDK Maven archetype for creating new projects
  • Loading branch information
srnagar authored Nov 22, 2021
1 parent e718d8d commit 6c168cf
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 1 deletion.
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ known_content_issues:
- ['sdk/storage/azure-storage-blob-nio/README.md', '#3113']
- ['sdk/storage/azure-storage-internal-avro/README.md', '#3113']
- ['sdk/storage/README.md', '#3113']
- ['sdk/tools/azure-sdk-archetype/README.md', '#3113']

package_indexing_exclusion_list:
- azure-loganalytics-sample
Expand Down
5 changes: 4 additions & 1 deletion eng/pipelines/templates/jobs/ci.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ parameters:
- name: UsePlatformContainer
type: boolean
default: false
- name: SkipAggregateReports
type: boolean
default: false

jobs:
- job: 'Test'
Expand Down Expand Up @@ -110,7 +113,7 @@ jobs:

- task: Maven@3
displayName: 'Generate aggregate code coverage report'
condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), eq('${{ parameters.SDKType }}', 'client'))
condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), eq('${{ parameters.SDKType }}', 'client'), eq('${{ parameters.SkipAggregateReports }}', 'false'))
inputs:
mavenPomFile: sdk/${{ parameters.ServiceDirectory }}/pom.xml
options: '$(DefaultOptions) -Pcoverage'
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ com.azure.resourcemanager:azure-resourcemanager-logz;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-storagepool;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-dataprotection;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-desktopvirtualization;1.0.0-beta.1;1.0.0-beta.2
com.azure.tools:azure-sdk-archetype;1.0.0;1.0.0

# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
# version. Unreleased dependencies are only valid for dependency versions.
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@
<module>sdk/template</module>
<module>sdk/textanalytics</module>
<module>sdk/timeseriesinsights</module>
<module>sdk/tools</module>
<module>sdk/translation</module>
<module>sdk/videoanalyzer</module>
<module>sdk/vmwarecloudsimple</module>
Expand Down
11 changes: 11 additions & 0 deletions sdk/tools/azure-sdk-archetype/CHANGELOG.md
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.
37 changes: 37 additions & 0 deletions sdk/tools/azure-sdk-archetype/README.md
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`.
70 changes: 70 additions & 0 deletions sdk/tools/azure-sdk-archetype/pom.xml
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>
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")
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>
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>
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!");
}
}
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
}
}
Loading

0 comments on commit 6c168cf

Please sign in to comment.