0

I am trying to exclude some java files from src/main/java and also some yml files from src/main/resources folder while building the jar using spring boot maven plugin. I have tried the following options:

Option 1 in maven-jar-plugin

<configuration>
    <excludes>
        <exclude>**/security/**/*.java</exclude>
        <exclude>**/application-*.yml</exclude>
    </excludes>
</configuration>

Option 2 resources in build tag:

<resources>
    <resource>
        <directory>src/main</directory>
            <excludes>
                <exclude>**/security/*</exclude>
                <exclude>**/application-*.yml</exclude>
            </excludes>
            <filtering>false</filtering>
    </resource>
</resources>

Option 1 and both are removing the java files from the generated jar.
But option 2 changes structure in JAR it includes java and resource folder.

Any pointer for the above is greatly appreciated.

Ganesh Shenoy
  • 619
  • 1
  • 10
  • 28
  • 1
    It seems strange that you want to ignore files from the source directory. Why are they in there in the first place? – J Fabian Meier Apr 11 '20 at 20:48
  • True. I agree. I have some REST API endpoints which helps me generate encrypted user id and password and also an endpoint to decrypt user credentials. I don't want it to be present in the PROD deployments and PROD is a different maven profile. Literally this should have been in different support project, but now it has to be in next phase. Please let me know if you have any other suggestions mentioned above regarding encrypt API. – Ganesh Shenoy Apr 11 '20 at 21:14
  • 1
    Using profiles to build different artifacts bad idea...furthermore if they should not being part of the resulting jar remove them. If they needed somewhere either they should be moved to test area (in case only for tests) otherwise you should make a separate module and build different spring boot apps... – khmarbaise Apr 11 '20 at 23:49
  • I do completely agree and is the right way. Thanks JF Meier and khmarbaise. Moved to different support project. Project deadlines!!! :) – Ganesh Shenoy Apr 12 '20 at 01:46

1 Answers1

0

I found solution, as following; it is using the maven jar plugin exclusions. There were issues in maven wildcard which was provided earlier.

Edit: Not the right approach to include java files which are removed while buliding artifact as suggested by JF Meier and khmarbaise. But solution is still valid for files exclusion.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/security/**</exclude>
            <exclude>**/application-*.yml</exclude>
        </excludes>
    </configuration>
</plugin>
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>repackage</id>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Ganesh Shenoy
  • 619
  • 1
  • 10
  • 28