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 no longer utilizes profile properties after a file was written to ${project.build.outputDirectory}/application-develop.properties #43366

Open
jg-cantaa opened this issue Sep 18, 2024 · 3 comments
Labels
area/config kind/bug Something isn't working triage/needs-feedback We are waiting for feedback.

Comments

@jg-cantaa
Copy link

Describe the bug

My original goal is to specify properties at build-time. (e.g. specifying quarkus.datasource.jdbc.url at build-time in CI)

I have a POM file with several profiles like this:

<profile>
      <id>azureDevops</id>
      <properties>
          <!--Azure Container Registry-->
          <quarkus.container-image.username>00000000-0000-0000-0000-000000000000</quarkus.container-image.username>
          <quarkus.container-image.image>${env.ACR_URL}/${project.artifactId}/${deployment}:latest</quarkus.container-image.image>
          <quarkus.container-image.build>true</quarkus.container-image.build>
          <quarkus.container-image.push>true</quarkus.container-image.push>

          <!--Kubernetes-->
          <jkube.namespace>${env.K8SNAMESPACE}</jkube.namespace>
          <jkube.generator.name>${env.ACR_URL}/${project.artifactId}/${deployment}:latest</jkube.generator.name>
          <quarkus.kubernetes.deployment-target>kubernetes</quarkus.kubernetes.deployment-target>

          <quarkus.jib.environment-variables.JAVA_APP_DIR>/deployments/data</quarkus.jib.environment-variables.JAVA_APP_DIR>
          <quarkus.jib.jvm-additional-arguments>-Xmx12G</quarkus.jib.jvm-additional-arguments>

          <maven.test.skip>true</maven.test.skip>
        </properties>
        </profile>
        <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <deployment>local</deployment>
            </properties>
        </profile>
        <profile>
        <id>develop</id>
        <properties>
            <deployment>develop</deployment>
            <quarkus.datasource.jdbc.url>jdbc:postgresql://${env.DB_HOST_DEVELOP}/odus_dev?currentSchema=max&amp;ApplicationName=MbcsSearch</quarkus.datasource.jdbc.url>
            <quarkus.datasource.password>${env.DB_ODUS_PASS_DEVELOP}</quarkus.datasource.password>
            <quarkus.datasource.username>${env.DB_ODUS_USER_DEVELOP}</quarkus.datasource.username>
            <zk.password>${env.SEARCH_ZK_ADMIN_PASSWORD_DEVELOP}</zk.password>
            <odus.password>${env.SEARCH_ODUS_ADMIN_PASSWORD_DEVELOP}</odus.password>
            <odus.secret>${env.SEARCH_ODUS_CLIENT_SECRET_DEVELOP}</odus.secret>
        </properties>
      </profile>

In CI we run maven with the profiles flag "-P azureDevops,$(branchName)". This configuration passes CI and deploys, but at runtime Quarkus complains that the Datasource is not configured:

Caused by: io.quarkus.runtime.configuration.ConfigurationException: Unable to find datasource '<default>' for persistence unit '<default>': Datasource '<default>' is not configured. To solve this, configure datasource '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.

This is somewhat expected as quarkus cannot read the properties from the pom. As a solution to this I have found the properties-maven-plugin from org.codehaus.mojo. Utilizing their plugin like this:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>write-active-profile-properties</goal>
                        </goals>
                        <configuration>
                            <outputFile>
                                ${project.build.outputDirectory}/application-${deployment}.properties
                            </outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Which I tested locally to produce an application-develop.properties in the target folder. Since quarkus uses the develop profile it should then load the values from there.

Expected behavior

I expected quarkus to not have a problem with this plugin, as it just writes properties to a file in the target folder.

Actual behavior

Once the plugin is added, quarkus fails with the message:

[ERROR] Caused by: com.google.cloud.tools.jib.api.RegistryAuthenticationFailedException: Failed to authenticate with registry registry-1.docker.io/agent/mbcs-search because: 401 Unauthorized
[ERROR] GET https://auth.docker.io/token?service=registry.docker.io&scope=repository:agent/mbcs-search:pull,push
[ERROR] {"details":"incorrect username or password"}

This indicates to me that it has problems with the properties set in the profile once the plugin is enabled.
Without the plugin it works fine.

I have even looked at the source of the plugin (https://github.com/mojohaus/properties-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java) to see if that messes with the properties, but I could not find a reason.

Once I tried to write the property file to ${project.build.outputDirectory}/test/test.properties
it passed CI again.

How to Reproduce?

No response

Output of uname -a or ver

Output of java -version

No response

Quarkus version or git rev

<quarkus.platform.version>3.7.4</quarkus.platform.version>

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /home/jakobgerhardt/.m2/wrapper/dists/apache-maven-3.9.6-bin/3311e1d4/apache-maven-3.9.6 Java version: 11.0.23, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: de_DE, platform encoding: UTF-8 OS name: "linux", version: "6.9.3-76060903-generic", arch: "amd64", family: "unix"

Additional information

I tried running this plugin in a different phase, but to no avail.

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 18, 2024

/cc @geoand (jib,kubernetes), @iocanel (kubernetes), @quarkusio/devtools (maven)

@geoand
Copy link
Contributor

geoand commented Sep 18, 2024

cc @radcortez

@radcortez
Copy link
Member

I've tried it, and it works. Do you have an application.properties sitting in the exact location? It is required to load profile properties files: https://quarkus.io/guides/config-reference#profile-aware-files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/bug Something isn't working triage/needs-feedback We are waiting for feedback.
Projects
None yet
Development

No branches or pull requests

3 participants