开发者

How do I exclude the sources jar in mvn deploy?

开发者 https://www.devze.com 2022-12-25 13:13 出处:网络
When I run \"mvn deploy:deploy\", maven deploys 4 jar files to my internal remote repository. They are:

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 configur开发者_StackOverflow中文版e the deployment file exclusion in pom.xml. Otherwise, I'll have to write a script to deploy.

Thanks,

Richard


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>


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)


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>


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>


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.


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?


<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>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号