How to include a file from a directory above in Maven src.xml?

127 Views Asked by At

I want to include the .gitignore file in my Maven project when it is getting packaged. (My university wants the file so they can see that I used it the right way)

But the .gitignore is on the workspace directory.

I know that I can add files from directorys below with this in my src.xml

<fileSet>
    <directory>src/test/resources</directory>
    <includes>
        <include>checkstyle_swt1.xml</include>
    </includes>
</fileSet>

But as the .gitignore isnt below src/ I dont know how to include it.

So far I have tried following:

<fileSet>
    <directory>C:/Users/Samue/OneDrive/SWTest</directory>
    <includes>
        <include>.gitignore</include>
    </includes>
</fileSet>

This didnt work unfortnuately. Any other ideas?

2

There are 2 best solutions below

0
Samuel On BEST ANSWER

Simply use ../../ and you also need to set default exludes to false

0
J Fabian Meier On

I find this requirement stupid because it is of no use in the final artifact. If the supervisor is interested in how you build the project, you should give him/her a zip of your artifact or workspace.

Anyway, the easiest way would be to copy the .gitignore to src/main/resources.

You can either do this manually, or you can attach the antrun plugin to an early phase of your lifecycle (https://stackoverflow.com/a/694175/927493).

For copying files with Ant see

https://ant.apache.org/manual/Tasks/copy.html