1

I'm trying to include the .gitignore file to the jar. I tried everything but it still not copying the .gitignore file. Here is my resources and jar plugins

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
          <configuration>
            <addDefaultExcludes>false</addDefaultExcludes>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <includes>.gitignore</includes>
          </configuration>
        </plugin>


I even tried maven-resources-plugin with 3.1.0, but it's not adding? How to achieve it?

Bharat
  • 21
  • 2
  • 1
    What if you'll put your `.gitignore` into the `main/resources` directory? or even into the `main/resources/my/package/name/.gitignore` ? – Max Daroshchanka Feb 08 '22 at 14:21
  • 2
    Why do you like to put the `.gitignore` into a jar file? That does not make sense... Please explain more in detail... – khmarbaise Feb 08 '22 at 14:26
  • 1
    Hi @khmarbaise, I'm creating the boilerplate for java. In that I'm specifying everything needed to create a maven project. For that I also need to put `.gitignore` – Bharat Feb 08 '22 at 14:33
  • 1
    Does this answer your question? [Maven-resources-plugin won't copy .metadata folder](https://stackoverflow.com/questions/25422298/maven-resources-plugin-wont-copy-metadata-folder) – pringi Feb 08 '22 at 14:45
  • 2
    First that will not work that work...furthermore there are so called archetypes for that... – khmarbaise Feb 08 '22 at 14:56
  • @Bharat The _. gitignore_ file tells Git which files to ignore when committing your project to the GitHub repository. This is the purpose of this file. There is absolutely no reason whatsoever why you would need this file in a JAR file. All you need to do is check in the _.gitignore_ file in your project so that everyone working on it has the same version. When you build your JAR, the _.gitignore_ should be ignored. – hfontanez Feb 08 '22 at 15:20

1 Answers1

1

Archetype jars are created by the archetype plugin. So you have to configure that by setting the useDefaultExcludes to false:

        <plugin>
          <artifactId>maven-archetype-plugin</artifactId>
          <configuration>
            <useDefaultExcludes>false</useDefaultExcludes>
          </configuration>
        </plugin>

Note that the configuration key is called useDefaultExcludes as opposed to addDefaultExcludes for resources plugin.

I don't know why people are saying it doesn't make sense to add .gitignore to an archetype jar. I find it very useful to make sure target/ and the like are automatically ignored.

Sjoerd Hemminga
  • 136
  • 1
  • 4