Skip to content

Per module versions #868

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>git-commit-id-plugin-core</artifactId>
<version>6.0.0</version>
<version>6.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ public class GitCommitIdMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.basedir}/.git")
File dotGitDirectory;

/**
* Configuration to tell the git-commit-id-maven-plugin to consider only
* commits affecting the folder containing this module, rather than all
* commits in the repository.
*/
@Parameter(defaultValue = "false")
boolean enablePerModuleVersions;

/**
* Configuration for the {@code 'git-describe'} command. You can modify the dirty marker, abbrev
* length and other options here. The following `gitDescribe` configuration below is optional and
Expand Down Expand Up @@ -1325,6 +1333,11 @@ public boolean getUseBranchNameFromBuildEnvironment() {
return useBranchNameFromBuildEnvironment;
}

@Override
public boolean getPerModuleVersions() {
return enablePerModuleVersions;
}

@Override
public boolean isOffline() {
return offline || settings.isOffline();
Expand Down Expand Up @@ -1404,6 +1417,11 @@ public boolean shouldPropertiesEscapeUnicode() {
public boolean shouldFailOnNoGitDirectory() {
return failOnNoGitDirectory;
}

@Override
public File getModuleBaseDir() {
return new File(project.getBasedir().getAbsolutePath());
}
};

GitCommitIdPlugin.runPlugin(cb, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -1716,6 +1717,48 @@ public void shouldGeneratePropertiesWithMultiplePrefixesAndReactorProject(boolea
}
}

@Test
public void shouldGiveCommitIdForEachFolderWhenPerModuleVersionsEnabled()
throws Exception {
// given
mavenSandbox
.withParentProject("parent-project", "pom")
.withChildProject("src/test", "jar")
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
.withKeepSandboxWhenFinishedTest(true)
.create();

// Only supported with JGit
mojo.useNativeGit = false;

// Don't skip the parent project
mojo.skipPoms = false;

//Enable per module versions
mojo.enablePerModuleVersions = true;

MavenProject parentProject = mavenSandbox.getParentProject(); // "my-pom-project"
MavenProject childProject = mavenSandbox.getChildProject(); // "my-child-module"

// when
// Execute the mojo in both parent and child projects
setProjectToExecuteMojoIn(parentProject);
mojo.execute();

setProjectToExecuteMojoIn(childProject);
mojo.execute();

// then
// The commit IDs should be different for parent and child projects
Properties parentProperties = parentProject.getProperties();
Properties childProperties = childProject.getProperties();

assertThat(parentProperties).containsKey("git.commit.id.abbrev");
assertThat(childProperties).containsKey("git.commit.id.abbrev");
assertThat(parentProperties.getProperty("git.commit.id.abbrev")).isNotEqualTo(childProperties.getProperty("git.commit.id.abbrev"));
}


private GitDescribeConfig createGitDescribeConfig(boolean forceLongFormat, int abbrev) {
GitDescribeConfig gitDescribeConfig = new GitDescribeConfig();
gitDescribeConfig.setTags(true);
Expand Down