1

In my maven pom, I have an additional jar-file that I'd like to include with my deployables. I've got the jar-file building successfully, and I figured I'd use the maven-deploy-plugin, like so (version-wise, I'm using 2.8.2 from dependencyManagement):

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-deploy-plugin</artifactId>
      <executions>
        <execution>
          <id>deploy-special-jar</id>
          <phase>deploy</phase>
          <goals>
            <goal>deploy-file</goal>
          </goals>
          <configuration>
            <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
            <url>${project.distributionManagement.repository.url}</url>
            <groupId>${project.groupId}</groupId>
            <artifactId>${project.artifactId}</artifactId>
            <version>${project.version}-special</version>
            <file>${project.build.directory}/special.jar</file>
          </configuration>
        </execution>
      </executions>
    </plugin>

This works great, but there's a slight issue. If you notice, the above pom is using project.distributionManagement.repository.url for both the repositoryId and url parameters. However, this means that regardless of if I'm building a snapshot or a release version, I'm always deploying to me release-area, which is not ideal. What if I'm building a snapshot? Well, the answer seems to be to change project.distributionManagement.repository.url to project.distributionManagement.snapshotRepository.url

I don't like the idea of changing these lines manually because I like to use the maven-release-plugin to switch between snapshot and release versions. Now, I'd have to add some scripting to change these lines each time. That's possible, but not ideal.

It seems that someone asked about this exact problem before back in 2008, and there wasn't really a good answer: http://maven.40175.n5.nabble.com/problems-with-the-maven-deploy-plugin-td107307.html So, I thought I'd add it here to see what people have come up with.

I'm considering using the build-helper plugin to dynamically change this property, but that seems like a potential rabbit-hole, especially since someone tried to do something similar before (for other reasons, but the concept is similar): Check if Maven pom is SNAPSHOT

So, what's the right answer here? Should this be a feature-request? Or, is there a simple way to work around this problem that people use? I'm curious what others have done. Has anyone had any luck with the build-helper plugin?

Thank you!

Community
  • 1
  • 1
  • 1
    Maybe a dumb q .. why does this jar have to be handled differently from all the other jars and artifacts that maven is building for you? – chrisinmtown Mar 10 '15 at 15:40
  • If it's really necessary to do a supplemental artifact (where i have my doubts) use the [build-helper-maven-plugin](http://mojo.codehaus.org/build-helper-maven-plugin/attach-artifact-mojo.html) which solves all of those problems with urls etc. – khmarbaise Mar 10 '15 at 15:47
  • The most important question is: How is the special.jar build? By Maven ? – khmarbaise Mar 10 '15 at 15:48
  • @khmarbaise Yes, it's built by maven. My current situation is that I need to make a regular jar as well as a second jar-file that is essentially the first one with some sensitive contents stripped out. Since this really is just an extension of the first jar, I thought that the quickest way to do this would be to copy the jarfile, and then run the truezip plugin to delete the right parts, and then re-upload with the maven-deploy-plugin. Perhaps my approach is wrong? – user2182758 Mar 10 '15 at 18:02
  • @chrislott I guess I could add another subproject to generate this special jarfile. It just seems easier in my particular case to want to make two jarfiles, since the special jar-file is essentially the already-built-by-maven jarfile, but with some of its contents stripped out. – user2182758 Mar 10 '15 at 18:04

1 Answers1

0

This sounds more like a second execution of maven-jar-plugin (after removing things) and this will result in automatic upload via mvn deploy no need to do such weird things...

Or may be using maven-assembly-plugin which creates a supplemental artifacts (one or more)...or maybe maven-shade-plugin. I'm not sure how you stripping out things...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I'm going to give this a shot. It seems like it will be an effective workaround, which is what I need at this point. I will admit that I am a little sad that the maven-deploy-plugin isn't as flexible as I hoped it could be. Maybe it's worth a feature-request. – user2182758 Mar 10 '15 at 20:05
  • maven-deploy-plugin is intended to deploy artifacts nothing more. Furthermore there are other better ways to solve this problems as mentioned. – khmarbaise Mar 10 '15 at 21:20