18

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
[module-name]-1-sources.jar
[module-name]-1-tests.jar

There are actually more files, such as md5 and sha1 files, being deployed. But for simplicity, I just skip these files here.

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

One way I can think of is to use "mvn deploy:deploy-file", which allows me to pinpoint which jar to deploy. But since I have a few dozen modules to deploy, it'll be nice if I can configure the deployment file exclusion in pom.xml. Otherwise, I'll have to write a script to deploy.

Thanks,
Richard

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Richard
  • 307
  • 2
  • 3
  • 6
  • FYI close question to not deploy "-tests.jar" se [here](http://stackoverflow.com/questions/8246136/maven-deploy-not-to-upload-test-jar) – boly38 Jul 31 '15 at 08:33

7 Answers7

24

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>
Matt F
  • 682
  • 5
  • 7
11

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)

Pino
  • 7,468
  • 6
  • 50
  • 69
  • For me this just did not work. Any other experience with this? – Clerenz Jan 11 '19 at 14:53
  • 2
    I think the right property is `-Dmaven.source.skip=true`, according to the official documentation: https://maven.apache.org/plugins/maven-source-plugin/jar-mojo.html – haridsv Jul 04 '19 at 15:26
  • @haridsv It seems that they changed the param name in v3. I updated my answer, thanks. – Pino Jul 05 '19 at 10:01
4

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>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • That's correct. I could remove the maven source plugin from the parent pom.xml. However, I would like to do this. I'd like to keep the maven source plugin in the parent POM. But provide a profile to disable the source plugin. This will be ideal, but not sure if it's doable. I'll give it a try. – Richard Apr 06 '10 at 01:23
  • @Richard I don't think you can "disable" a plugin in a profile so you'll have to do it the other way: put the `maven-source-plugin` declaration in a profile (activated by default for example) and remove the profile during release: `mvn -P!my-profile deploy` – Pascal Thivent Apr 06 '10 at 01:40
4

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>
S.K. Venkat
  • 1,749
  • 2
  • 23
  • 35
2

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.

aperkins
  • 12,914
  • 4
  • 29
  • 34
1

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?
kopper
  • 2,676
  • 1
  • 16
  • 17
  • @koppernickus we keep sources in the release repo but not the snapshot repo. This might actually be a common practice in industries where versions of products need to be audited by outside entities. – sal Apr 05 '10 at 21:01
  • 1
    @sal Please consider using mvn-release-plugin (http://maven.apache.org/plugins/maven-release-plugin/) for any artifacts being released to non-snapshot repository. The process looks like follows: 1. for snapshots (assuming that this is the most often case): just do "mvn clean install" -> remove source as attached artifact. 2. for release (assuming this is rarely used): execute mvn release:prepare and then mvn:perform Anyways - if you need slightly different ("heavier") process for releases than snapshots at leat try this plugin. In our case it works very well. – kopper Apr 05 '10 at 21:09
  • This was in response of question 2. We do use a deploy profile with the release plugin that automates the process. And yes, it is heavy. But the auditing process is _much_ heavier. – sal Apr 05 '10 at 21:33
  • We want to provide the binary jars for a third party to build, but we don't want to provide our source code. – Richard Apr 06 '10 at 01:25
1
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>
    <configuration>
        <attach>false</attach>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>           
        </execution>
    </executions>
</plugin>

The attach parameter specifies whether the java sources will be attached to the artifact list of the project.
<attach>false</attach>

eric.zsp
  • 11
  • 1