Eclipse在自动构建循环中使用m2e和git-commit-id-plugin来生成资源

时间:2014-06-21 01:45:16

标签: eclipse m2e

我正在使用Eclipse(试过Juno和Kepler)和m2e。一切正常,直到我尝试使用git-commit-id-plugin生成我的git构建的属性(git.properties)文件(分支名称,标记名称,构建时间等)。这是目录层次结构。

.classpath
.project
.settings/org.eclipse.jdt.core.prefs
.settings/org.eclipse.m2e.core.prefs
pom.xml
src/git.properties (Generated file)

我认为此处的问题是eclipse/m2e中的自动构建会生成git.properties。之后,由于更新git.properties,它将触发另一个自动构建。

有没有办法告诉eclipse不要“看”src/git.properties

上面提到的所有文件都附在下面:

的.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" output="target/classes" path="src">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="output" path="target/classes"/>
</classpath>

的.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>testMavenEclipseAutoBuild</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
</projectDescription>

.settings / org.eclipse.jdt.core.prefs

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

.settings / org.eclipse.m2e.core.prefs

activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

的pom.xml

<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>testMavenEclipseAutoBuild</groupId>
        <artifactId>testMavenEclipseAutoBuild</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>test</name>
        <build>
                <sourceDirectory>src</sourceDirectory>
                <plugins>
                        <plugin>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.1</version>
                                <configuration>
                                        <source>1.6</source>
                                        <target>1.6</target>
                                </configuration>
                        </plugin>
                        <plugin>
                                <!-- Ref: https://github.com/ktoso/maven-git-commit-id-plugin#using-the-plugin -->
                                <groupId>pl.project13.maven</groupId>
                                <artifactId>git-commit-id-plugin</artifactId>
                                <version>2.1.10</version>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>revision</goal>
                                                </goals>
                                        </execution>
                                </executions>

                                <configuration>
                                        <generateGitPropertiesFile>true</generateGitPropertiesFile>
                                        <generateGitPropertiesFilename>src/git.properties</generateGitPropertiesFilename>
                                </configuration>

                        </plugin>
                </plugins>
        </build>
</project>

3 个答案:

答案 0 :(得分:0)

右键单击该项目,选择Properties/Resource/Resource Filter并添加排除所有规则以从资源中排除文件git.properties

这对我有用。

答案 1 :(得分:0)

您可能想要修改generateGitPropertiesFilename,以便在target / classes目录中生成git.properties。

<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>

答案 2 :(得分:0)

您可以修改eclipse生命周期 - 映射 - 元数据。

请参阅this site.

上的第4.2节

添加以下代码:

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <versionRange>[2.1,)</versionRange>
                <goals>
                    <goal>revision</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
    </pluginExecutions>
</lifecycleMappingMetadata>