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

Can't use generated properties when building maven #601

Closed
qianlong opened this issue Mar 9, 2023 · 3 comments
Closed

Can't use generated properties when building maven #601

qianlong opened this issue Mar 9, 2023 · 3 comments
Milestone

Comments

@qianlong
Copy link

qianlong commented Mar 9, 2023

The properties generated by this plugin can't be used directly as those declared in <properties>.

Steps to Reproduce

  • Please include the full configuration of the plugin
<plugin>
	<groupId>io.github.git-commit-id</groupId>
	<artifactId>git-commit-id-maven-plugin</artifactId>
	<version>5.0.0</version>
	<executions>
		<execution>
			<id>get-the-git-infos</id>
			<goals>
				<goal>revision</goal>
			</goals>
			<phase>initialize</phase>
		</execution>
	</executions>
	<configuration>
		<generateGitPropertiesFile>true</generateGitPropertiesFile>
		<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
		<includeOnlyProperties>
			<includeOnlyProperty>^git.branch.*$</includeOnlyProperty>
		</includeOnlyProperties>
		<injectAllReactorProjects>true</injectAllReactorProjects>
		<replacementProperties>
			<replacementProperty>
				<property>git.branch</property>
				<propertyOutputSuffix>version</propertyOutputSuffix>
				<token>^(feature/.+|dev)$</token>
				<value>dev</value>
			</replacementProperty>
		</replacementProperties>
	</configuration>
</plugin>

Expected behavior

  • To use the generated git.branch.version as property in dependency version.
@TheSnoozer
Copy link
Collaborator

Mhh tested this locally and the plugin is generating the property git.branch.version as expected.

For debugging I'd suggest to add <verbose>true</verbose> to the configuration of the plugin.

I'd almost guess that the project where the plugin is running is pom project (<packaging>pom</packaging>). For that the plugin is skipped by default:

[INFO] --- git-commit-id-maven-plugin:5.0.0:revision (get-the-git-infos) @ git-commit-id-plugin-debugging ---
[INFO] isPomProject is true and skipPoms is true, return

Here is what I tested for reference:

			<plugin>
				<groupId>io.github.git-commit-id</groupId>
				<artifactId>git-commit-id-maven-plugin</artifactId>
				<version>5.0.0</version>
				<executions>
					<execution>
						<id>get-the-git-infos</id>
						<goals>
							<goal>revision</goal>
						</goals>
						<phase>initialize</phase>
					</execution>
				</executions>
				<configuration>
					<verbose>true</verbose>
					<skipPoms>false</skipPoms>
					<generateGitPropertiesFile>true</generateGitPropertiesFile>
					<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
					<includeOnlyProperties>
						<includeOnlyProperty>^git.branch.*$</includeOnlyProperty>
					</includeOnlyProperties>
					<injectAllReactorProjects>true</injectAllReactorProjects>
					<replacementProperties>
						<replacementProperty>
							<property>git.branch</property>
							<propertyOutputSuffix>version</propertyOutputSuffix>
							<token>^(feature/.+|dev)$</token>
							<value>dev</value>
						</replacementProperty>
					</replacementProperties>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.8</version>
				<executions>
					<execution>
						<phase>package</phase>
						<configuration>
							<target>
								<echo>===========================================================================</echo>
								<echo>git.branch.version: ${git.branch.version}</echo>
							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

generates

[INFO] --- git-commit-id-maven-plugin:5.0.0:revision (get-the-git-infos) @ git-commit-id-plugin-debugging ---
[INFO] dotGitDirectory /workspace/git-commit-id/git-commit-id-debugging/.git
[INFO] Collected git.branch with value master
[INFO] Added properties to 3 projects
[INFO] apply replace on property git.branch and save to git.branch.version: original value 'master' with 'master'
[INFO] including property git.branch in results
[INFO] including property git.branch.version in results
[INFO] Writing properties file to [/workspace/git-commit-id/git-commit-id-debugging/target/classes/git.properties] (for module Git Commit Id Plugin Maven Mojo Debugging)...
[INFO] Added properties to 3 projects
[INFO] 
[INFO] --- maven-antrun-plugin:1.8:run (default) @ git-commit-id-plugin-debugging ---
[INFO] Executing tasks

main:
     [echo] ===========================================================================
     [echo] git.branch.version: master

@qianlong
Copy link
Author

qianlong commented Mar 10, 2023

Thanks for your response, the property is generated as expected, but can't be used in project and dependencies' version.
The packaging is not pom.
What I was trying to do is to run mvn install and mvn deploy with generated version. But I've got an error when running mvn deploy:

'dependencies.dependency.version' for test.group:test1:jar must be a valid version but is '${git.branch.version}-SNAPSHOT'

<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>test.group</groupId>
	<artifactId>test2</artifactId>
	<version>${revision}-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<dependency.version>${git.branch.version}-SNAPSHOT</dependency.version>
		<revision>${git.branch.version}</revision>
	</properties>

	<dependencies>
		<dependency>
			<groupId>test.group</groupId>
			<artifactId>test1</artifactId>
			<version>${dependency.version}</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>io.github.git-commit-id</groupId>
				<artifactId>git-commit-id-maven-plugin</artifactId>
				<version>5.0.0</version>
				<executions>
					<execution>
						<id>get-the-git-infos</id>
						<goals>
							<goal>revision</goal>
						</goals>
						<phase>initialize</phase>
					</execution>
				</executions>
				<configuration>
					<generateGitPropertiesFile>true</generateGitPropertiesFile>
					<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
					<includeOnlyProperties>
						<includeOnlyProperty>^git.branch.*$</includeOnlyProperty>
					</includeOnlyProperties>
					<forceValueEvaluation>true</forceValueEvaluation>
					<injectIntoSysProperties>true</injectIntoSysProperties>
					<replacementProperties>
						<replacementProperty>
							<property>git.branch</property>
							<propertyOutputSuffix>version</propertyOutputSuffix>
							<token>^(feature/.+|dev)$</token>
							<value>dev</value>
						</replacementProperty>
						<replacementProperty>
							<property>git.branch</property>
							<propertyOutputSuffix>version</propertyOutputSuffix>
							<token>master</token>
							<value>uat</value>
							<regex>false</regex>
						</replacementProperty>
					</replacementProperties>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

@TheSnoozer
Copy link
Collaborator

TheSnoozer commented Mar 11, 2023

This is unsupported:
https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/docs/faq.md#generated-properties-are-not-being-used-in-install-andor-deploy

Attempt to use the workarounds suggested, or solutions like generating the pom on the fly with the flatten-maven-plugin.

See also #256 (comment) et. al.

@TheSnoozer TheSnoozer added this to the 6.0.0 milestone May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants