How do I exclude the sources jar in mvn deploy?

后端 未结 7 901
半阙折子戏
半阙折子戏 2021-01-01 17:03

When I run \"mvn deploy:deploy\", maven deploys 4 jar files to my internal remote repository.

They are:

[module-name]-1.jar
[module-name]-1.pom
[modu

相关标签:
7条回答
  • 2021-01-01 17:06

    As of version 2.2 of the maven-source-plugin you can skip source generation with a config option without having to put the plugin in a profile in your parent pom:

      <!-- Do not generate a source jar -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <configuration>
          <skipSource>true</skipSource>
        </configuration>
      </plugin>
    
    0 讨论(0)
  • 2021-01-01 17:11

    Let me assume that you shoudn't skip generating sources for a module. In that case, this would be a simple solution which helps you to handle this scenario :

    In the execution part of "maven-source-plugin" under plugins section, set the attach attribute to false. This configuration will generate the sources.jar for your module, but not attached it to the project's artifact list.

    The example snippet is here:

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${source.plugin.version}</version>
            <executions>
                <execution>
                    <id>module1-sources</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                    <configuration>
                        <!-- The below specified attribute 'attach' will disable the sources.jar not included in the artifact list -->
                        <attach>false</attach>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    
    0 讨论(0)
  • 2021-01-01 17:17

    Deploy plugin maven site:

    http://maven.apache.org/plugins/maven-deploy-plugin/index.html

    Based on what I am reading there, it looks like you can exclude modules from deployment, but not individual files - at least not yet.

    If you look at the goals page:

    http://maven.apache.org/plugins/maven-deploy-plugin/plugin-info.html

    it does not show any specific configurations of the plugin for what you are looking for. As the goals page is made from the plugin class, by looking at the annotations, I would say that they do not have the ability.

    One thing you could do would be to make a different build that does not create the jars you don't want created - i.e. make a different assembly package or the like for that build, and have the build be run when you are trying to deploy specific packages.


    Edit: koppernickus has a full description of this, I would recommend you see his post.

    0 讨论(0)
  • 2021-01-01 17:22

    Is there any way to exclude [module-name]-1-sources.jar from the deployment process?

    Don't generate sources if you don't want to deploy them. So either remove the following (that you must have in your POM) or put it in a profile that you don't use or exclude during release (I wonder when you use sources in that case):

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <executions>
            <execution>
              <goals>
                <goal>jar</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    
    0 讨论(0)
  • 2021-01-01 17:26

    Maven mvn deploy:deploy deploys all produced artifacts during maven process (default lifecycle). To not deploy [module-name]-1-sources.jar you should simply(?) not produce one. If you are using maven-source-plugin to attach source files just don't use it anymore.

    If this is not the case you are experiencing please provide more details:

    1. how do you generate [module-name]-1-sources.jar artifact (which plugin generate this artifact?)
    2. why do you need to generate sources but you don't need deploy them to the repository?
    0 讨论(0)
  • 2021-01-01 17:27

    If you don't want modify your POM, you can skip sources jar creation by adding an enviroment variable to command line:

    -Dsource.skip (for maven-source-plugin up to version 2.4, see 2.4 doc)

    or

    -Dmaven.source.skip (for maven-source-plugin version 3.0.0+, see 3.0.1 doc or the latest one)

    0 讨论(0)
提交回复
热议问题