azure-maven-plugins icon indicating copy to clipboard operation
azure-maven-plugins copied to clipboard

Validation of the 'function artifact' should respect value of 'finalName' passed via plugin configuration when running "package". Variant on #1136

Open agilette opened this issue 3 years ago • 1 comments

Plugin name and version

Plugin: azure-functions-maven-plugin:1.14.2 Maven version: Apache Maven 3.8.1

Plugin configuration in your pom.xml

<plugin>
				<groupId>com.microsoft.azure</groupId>
				<artifactId>azure-functions-maven-plugin</artifactId>
				<configuration>
					<resourceGroup>${functionResourceGroup}</resourceGroup>
					<appName>${functionAppName}</appName>
					<region>${functionAppRegion}</region>
					<subscriptionId>${subscription}</subscriptionId>
					<finalName>${project.build.finalName}-runner</finalName>
					<runtime>
						<os>windows</os>
						<javaVersion>11</javaVersion>
					</runtime>
					<appSettings>
						<property>
							<name>FUNCTIONS_EXTENSION_VERSION</name>
							<value>~4</value>
						</property>
						<property>
							<name>FUNCTIONS_WORKER_RUNTIME</name>
							<value>java</value>
						</property>
					</appSettings>
				</configuration>
			</plugin>
			<plugin>
				<groupId>${quarkus.platform.group-id}</groupId>
				<artifactId>quarkus-maven-plugin</artifactId>
				<extensions>true</extensions>
				<executions>
					<execution>
						<goals>
							<goal>build</goal>
							<goal>generate-code</goal>
							<goal>generate-code-tests</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

Expected behavior

Running mvn package azure-functions:package should successfully produce package.

The PackageMojo.getArtifactFile() method should correctly find my jar even if it it has a different name to the value of project.build.finalName, which may differ due to the action of other plugins.

Actual behavior

The PackageMojo.getArtifactFile() method doesn't allow the finalName to be overridden in the plugin configuration, and instead goes directly to project.getBuild().getFinalName(). As a result, it fails my build as the name has been customised by another plugin (specifically in my case: io.quarkus:quarkus-maven-plugin, which appends the name with -runner, and while this can be changed, it can't be blank).

This is almost the same error as #1135, but occuring on package goal rather than deploy goal

[ERROR] Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.14.2:package (default-cli) on project eip: Failed to parse artifact compile version. D:\stuff\eip\target\eip-0.0.1-SNAPSHOT.jar -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.14.2:package (default-cli) on project eip: Failed to parse artifact compile version. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289) at org.apache.maven.cli.MavenCli.main(MavenCli.java:193) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347) Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to parse artifact compile version. at com.microsoft.azure.maven.AbstractAzureMojo.onMojoError(AbstractAzureMojo.java:578) at com.microsoft.azure.maven.AbstractAzureMojo.execute(AbstractAzureMojo.java:497) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210) ... 20 more Caused by: com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException: Failed to parse artifact compile version. at com.microsoft.azure.toolkit.lib.common.utils.Utils.getArtifactCompileVersion(Utils.java:64) at com.microsoft.azure.maven.function.PackageMojo.promptCompileInfo(PackageMojo.java:416) at com.microsoft.azure.maven.function.PackageMojo.doExecute(PackageMojo.java:114) at com.microsoft.azure.maven.AbstractAzureMojo.execute(AbstractAzureMojo.java:492) ... 22 more Caused by: java.nio.file.NoSuchFileException: D:\stuff\eip\target\eip-0.0.1-SNAPSHOT.jar at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53) at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38) at java.base/sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:199) at java.base/java.nio.file.Files.readAttributes(Files.java:1843) at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1230) at java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:707) at java.base/java.util.zip.ZipFile.(ZipFile.java:241) at java.base/java.util.zip.ZipFile.(ZipFile.java:171) at java.base/java.util.jar.JarFile.(JarFile.java:348) at java.base/java.util.jar.JarFile.(JarFile.java:319) at java.base/java.util.jar.JarFile.(JarFile.java:285) at com.microsoft.azure.toolkit.lib.common.utils.Utils.getArtifactCompileVersion(Utils.java:50) ... 25 more

Steps to reproduce the problem

Generate a .jar and place it in the staging directory under any name other than project.build.finalName and then run azure-functions:package.

Suggested solution

rework in the same way as #1136

agilette avatar Mar 07 '22 04:03 agilette

@agilette Thanks for your report, I'll investigate this issue soon, and will update here once there are updates

Flanker32 avatar Mar 07 '22 11:03 Flanker32