0

I would like to generate a sources jar file for my project, so I have included the maven-source-plugin. However, I am also using the resource filtering plugin to set a version number in a property file for my project. When I generate a final jar file, the property file has been filtered and the version is set. However in the sources jar, is still has the unfiltered property. I would like for the sources plugin to also invoke the resource filtering. How can I do this?

Here is (part) of my pom.xml

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

and here is the property file that I want filtered in

version = ${project.version}

EDIT

For clarification, the root of my issue is that I have another project that is a GWT project built using this library. Part of the requirements of a GWT project is that the source code has to also be made available for anything that is going to be compiled to client side javascript. Therefore, this project contains both the compiled jar and the sources jar in the classpath.

So there are now two properties files with the same package path and name, one exists in the compiled jar and one in the sources jar.

When I attempt to read this file, it seems to pick the properties file out of the sources jar, which has not been filtered.

  • A source jar's contains the source of your project nothing filtered, nothing compiled etc. Apart from that setting `` and `` does not make sense cause these are the default. (Convention over Configuration). – khmarbaise Feb 23 '17 at 16:18
  • @khmarbaise Thank you for pointing out the duplicate configuration information in my pom, I will certainly remove that. I did add extra information as to why I would like for the source jar resources filtered. I can understand that it is technically incorrect, so I added the actual problem I am encountering. – Michael Kitzman Feb 23 '17 at 17:58
  • How about filtering the property in the generate-resource phase instead? – Thomas Broyer Feb 23 '17 at 19:21
  • Or instead of filtering, you can uses properties and access them using System.getProperty. Example here https://github.com/ibaca/gwt-dagger2-coffee/blob/master/pom.xml – Ignacio Baca Feb 23 '17 at 23:01
  • @IgnacioBaca, Using System.getProperty would work if i were running this via maven. I do not think this property would carry over if I build a war file and deploy my war file. – Michael Kitzman Feb 24 '17 at 20:20
  • @ThomasBroyer You will have to excuse my Maven ignorance here, but how would I go about attaching the property filtering to a different phase? – Michael Kitzman Feb 24 '17 at 20:21

1 Answers1

0

Normally, you'd use the maven-source-plugin for this. However, I see in its documentation that you cannot remove src/main/resources from its processing, while simultaneously adding target/classes to its processing cycle (which is what you would need to do in order to accomplish your task)

Therefore, I think your best bet is through a maven-assembly-plugin configuration.

Andrei
  • 1,613
  • 3
  • 16
  • 36
  • Unfortunately for the time being, I am simply setting the version number manually in my properties file, until I can get a good work flow defined. – Michael Kitzman Mar 02 '17 at 20:34