Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus Maven Plugin : can't use properties generated by maven build-helper #14788

Closed
rmanibus opened this issue Feb 3, 2021 · 9 comments · Fixed by #14809
Closed

Quarkus Maven Plugin : can't use properties generated by maven build-helper #14788

rmanibus opened this issue Feb 3, 2021 · 9 comments · Fixed by #14809

Comments

@rmanibus
Copy link
Contributor

rmanibus commented Feb 3, 2021

Describe the bug

quarkus configuration property containing values generated by maven build-helper regex-property make the quarkus maven plugin fail.
I'm able to display the content of those configuration properties with antrun plugin.

   <properties>
        <!--
          this is working:
         <quarkus.container-image.tag>${project.version}-${git.branch}</quarkus.container-image.tag>
          this does not work:
        -->
        <quarkus.container-image.tag>${project.version}-${git.safebranch}</quarkus.container-image.tag>
        <!--
            The value of quarkus.container-image.tag is correctly expanded in the maven antrun plugin below
             <echo>[git.branch] ${git.branch}</echo>
             <echo>[git.safebranch] ${git.safebranch}</echo>
             <echo>[quarkus.container-image.tag] ${quarkus.container-image.tag}</echo>
        -->

    </properties>
    <build>
       <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.0.0</version>
                <executions>
                    <execution>
                        <id>git-infos</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <configuration>
                            <includeOnlyProperties>
                                <inclueOnlyProperty>^git.branch$</inclueOnlyProperty>
                            </includeOnlyProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>regex-property</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>regex-property</goal>
                        </goals>
                        <configuration>
                            <name>git.safebranch</name>
                            <value>${git.branch}</value>
                            <regex>/</regex>
                            <replacement>-</replacement>
                            <failIfNoMatch>false</failIfNoMatch>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- quarkus.container-image.tag is correctly expanded here, but not in the quarkus maven plugin -->
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo>[git.branch] ${git.branch}</echo>
                                <echo>[git.safebranch] ${git.safebranch}</echo>
                                <echo>[quarkus.container-image.tag] ${quarkus.container-image.tag}</echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            [...]
       </plugins>
   </build>

Expected behavior
(Describe the expected behavior clearly and concisely.)

Actual behavior

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.11.1.Final:build (default) on project reproducer: Failed to build quarkus application: java.util.NoSuchElementException: SRCFG00011: Could not expand value git.safebranch in property quarkus.container-image.tag -> [Help 1

To Reproduce
here is a reproducer
https://github.com/rmanibus/quarkus_14788

Steps to reproduce the behavior:
just run mvn install

Environment (please complete the following information):

  • Output of uname -a or ver: ubuntu 20.10
  • Output of java -version: tested on jdk 8 & 15
  • Quarkus version or git rev: latest
  • mvn 3.6.3
@rmanibus rmanibus added the kind/bug Something isn't working label Feb 3, 2021
@ghost ghost added the area/maven label Feb 3, 2021
@ghost
Copy link

ghost commented Feb 3, 2021

/cc @quarkusio/devtools

@aloubyansky
Copy link
Member

It is in fact present among the build properties but when we are creating a ConfigSource out of those we are filtering out everything that doesn't start with the quarkus. prefix.
I am wondering whether we should allow users to control about what extra props should be made available in the config.
Just in case, @radcortez

@radcortez
Copy link
Member

@rmanibus can you add a complete stacktrace please?

@aloubyansky
Copy link
Member

Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value git.safebranch in property quarkus.container-image.tag
    at io.smallrye.config.ExpressionConfigSourceInterceptor.lambda$getValue$0 (ExpressionConfigSourceInterceptor.java:44)
    at io.smallrye.common.expression.ExpressionNode.emit (ExpressionNode.java:22)
    at io.smallrye.common.expression.CompositeNode.emit (CompositeNode.java:22)
    at io.smallrye.common.expression.Expression.evaluateException (Expression.java:56)
    at io.smallrye.common.expression.Expression.evaluate (Expression.java:70)
    at io.smallrye.config.ExpressionConfigSourceInterceptor.getValue (ExpressionConfigSourceInterceptor.java:37)
    at io.smallrye.config.ExpressionConfigSourceInterceptor.getValue (ExpressionConfigSourceInterceptor.java:18)
    at io.smallrye.config.SmallRyeConfigSourceInterceptorContext.proceed (SmallRyeConfigSourceInterceptorContext.java:20)
    at io.smallrye.config.SmallRyeConfig.getConfigValue (SmallRyeConfig.java:192)
    at io.smallrye.config.SmallRyeConfig.getValue (SmallRyeConfig.java:149)
    at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.readConfigValue (BuildTimeConfigurationReader.java:621)
    at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.readConfigGroup (BuildTimeConfigurationReader.java:566)
    at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.run (BuildTimeConfigurationReader.java:294)
    at io.quarkus.deployment.configuration.BuildTimeConfigurationReader.readConfiguration (BuildTimeConfigurationReader.java:250)
    at io.quarkus.deployment.ExtensionLoader.loadStepsFrom (ExtensionLoader.java:181)
    at io.quarkus.deployment.QuarkusAugmentor.run (QuarkusAugmentor.java:101)
    at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment (AugmentActionImpl.java:306)
    at io.quarkus.runner.bootstrap.AugmentActionImpl.createProductionApplication (AugmentActionImpl.java:141)
    at io.quarkus.maven.BuildMojo.doExecute (BuildMojo.java:104)
    at io.quarkus.maven.QuarkusBootstrapMojo.execute (QuarkusBootstrapMojo.java:85)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    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 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)

@rmanibus
Copy link
Contributor Author

rmanibus commented Feb 3, 2021

@aloubyansky but why is it able to expand ${git.branch} and >${project.version} then ?

I confirm that replacing ${git.safebranch} by ${quarkus.git.safebranch} make the reproducer work as expected.

@radcortez
Copy link
Member

The issue is that we try to expand the variable, but since it was not included in the source the expansion fails. What we can do is to also include any properties required for expansion.

@aloubyansky
Copy link
Member

That makes sense @radcortez

@rmanibus because the git-commit-id-plugin also sets those properties as system properties by default. If you change your config to

-        <quarkus.container-image.tag>${project.version}-${git.safebranch}</quarkus.container-image.tag>
+        <quarkus.container-image.tag>${project.version}-${git.branch}</quarkus.container-image.tag>
         <!--
             The value of quarkus.container-image.tag is correctly expanded in the maven antrun plugin below
              <echo>[git.branch] ${git.branch}</echo>
@@ -84,6 +84,7 @@
                             <includeOnlyProperties>
                                 <inclueOnlyProperty>^git.branch$</inclueOnlyProperty>
                             </includeOnlyProperties>
+                            <injectIntoSysProperties>false</injectIntoSysProperties>

it will fail in the same way as the git.safebranch.

@radcortez
Copy link
Member

Great. I'll have a look into this later.

@rmanibus
Copy link
Contributor Author

rmanibus commented Feb 3, 2021

this make sense, thanks !

@gsmet gsmet added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Feb 4, 2021
@quarkus-bot quarkus-bot bot added this to the 1.14 - main milestone Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants