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

Allow to generate git.properties file AND add properties to maven project properties #391

Closed
Kshekhovtsova opened this issue Oct 18, 2018 · 6 comments

Comments

@Kshekhovtsova
Copy link

I would like if plugin allow me to generate git.properties file along with adding properties to maven project properties. Currently there is only boolean parameter generateGitPropertiesFile which allow to generate file OR to add properties to maven properties, but in my project it is necessary to do both of these things.

I suggest to add a new boolean parameter addToMavenProperties which enables/disables adding properties to maven properties. Then it should be checked that at least one of this two parameters is true.

@TheSnoozer
Copy link
Collaborator

Hi,
thanks for reporting your issue here, but as far as I get your problem you also want to be able to use the generated properties within the pom? Please correct me if I missundertsood that, but that could be achieved by using <injectAllReactorProjects>true</injectAllReactorProjects>.

Full example:

<plugins>
    <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
        <version>2.2.5</version>
        <executions>
            <execution>
                <goals>
                    <goal>revision</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <prefix>git</prefix>
            <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
            <injectAllReactorProjects>true</injectAllReactorProjects>
            <generateGitPropertiesFile>true</generateGitPropertiesFile>
            <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        </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>Git-Infos: ${git.commit.id}</echo>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

@Kshekhovtsova
Copy link
Author

Kshekhovtsova commented Oct 19, 2018

Thank you for your reply! I didn't tried this parameter before. After I read the documentation I thought it is not appropriate in my case because I don't have any reactor projects (git submodules) in my project. In the description of parameter it's said that:

Set this to true to inject git properties into all reactor projects, not just the current one. Injecting into all projects may slow down the build and you don't always need this feature.
See #65 for details about why you might want to skip this.

but I just want these properties to inject into my project along with generating file, but not injecting it into any other reactor projects. Setting injectAllReactorProjects to true actually solves my problem and by the way build didn't slow down, but I'm not sure these parameter will benefit if I had to add git submodules some day without the need to inject git properties to them. So I think it would be a good decision if the logic of injecting properties in maven project will be divided from injecting properties to it's git submodules :)

@TheSnoozer
Copy link
Collaborator

Mhh I think there might be a bit of a confusion about the different terms. Let me try to clarify what the <injectAllReactorProjects>true</injectAllReactorProjects> actually means.

In general a maven project can consist either of a single pom, or a multi project build. The multi project build is usually called a reactor build (see https://maven.apache.org/guides/mini/guide-multiple-modules.html for a better explanation or more details and checkout https://github.com/TheSnoozer/git-commit-id-debugging/ that contains a project that uses the multi module feature). In maven terminology the top level pom is usually called parent or root and the projects below submodule.

When you set <injectAllReactorProjects>true</injectAllReactorProjects> what happens is that the generated properties of the git are exposed to all submodules and the parent. In other words the properties are available/injected into all projects that are part of the multi module build. Setting this configuration to true might to things a user doesn't want to happen for whatever reasons.

Gitmodules on the other hand is a slightly different concept and you can find more information under https://git-scm.com/book/en/v2/Git-Tools-Submodules. Gitmodules is the concept where you have a git project and need another git project within (maybe some shared code or configuration settings for your IDE).

Using git submodules is independent to using a maven reactor. You can use the concept of git submodules with a single pom build, or a multi project build (reactor).

If I understand it correctly you want to be able to get the properties of your normal git project and the git properties of your git submodule and expose them both as git properties and to the maven project. If this is the case I would say that's the same problem as running the plugin multiple times with different git projects (technically I consider a git submodule a different git since it would result in different properties). In such a case please checkout my answer in #137 (comment) where I outline how one could run the plugin multiple times with different git projects without overwriting already generated properties. Please note that in your case you might want to extend this configuration with <injectAllReactorProjects>true</injectAllReactorProjects>.

Hope this helps. Please feel free to let me know if you need further help :-)

@TheSnoozer
Copy link
Collaborator

Ohh and before I forget to mention...if you experience that this plugin might run slow, I would recommend to checkout and play around with the <useNativeGit> parameter. In my experience with the plugin the native git binary is usually faster than our own custom jgit implementation. jgit is essentially the java implementation of git.

To use the native git (might make the build faster) set <useNativeGit>true</useNativeGit> in your pom.

@TheSnoozer
Copy link
Collaborator

Hi,
I just wanted to check if the above answered your question / solved your problem.
Let me know if you have any other question

@Kshekhovtsova
Copy link
Author

Hi,
I just wanted to check if the above answered your question / solved your problem.
Let me know if you have any other question

Now everything's clear to me. Thanks for help! My problem is solved now and this issue could be closed I suppose.

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