Sebastien Diot
Sebastien Diot

Reputation: 7369

Maven: No primary artifact to install, installing attached artifacts instead

I have a parent Maven POM that looks like this (the oss-parent can be seen here):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.blockwithme</groupId>
        <artifactId>oss-parent</artifactId>
        <version>0.0.5</version>
    </parent>

    <groupId>com.blockwithme</groupId>
    <artifactId>xtend-contrib-parent</artifactId>
    <version>0.0.3</version>
    <packaging>pom</packaging>
    <inceptionYear>2013</inceptionYear>
    <name>Xtend Contrib Parent</name>
    <dependencies>
        <dependency>
            <groupId>org.eclipse.xtend</groupId>
            <artifactId>org.eclipse.xtend.lib</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.xtend</groupId>
            <artifactId>org.eclipse.xtend.core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.xtend</groupId>
                <artifactId>xtend-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <modules>
        <module>base</module>
        <module>examples</module>
    </modules>
</project>

With a child "base" POM that looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.blockwithme</groupId>
        <artifactId>xtend-contrib-parent</artifactId>
        <version>0.0.3</version>
    </parent>
    <artifactId>xtend-contrib-base</artifactId>
</project>

It creates and install the child Jar in the local repo. But I would like to install the source and/or javadoc too. So I add this to the parent POM:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
</plugin>

But if I do that, the source and javadoc get installed, but the compiled code jar stops being installed, which makes no sense to me. Maven gives this warning:

[INFO] No primary artifact to install, installing attached artifacts instead.

Which does not appear, if I do not try to get the source installed. Adding the maven-jar-plugin plugin does not help. Nor does adding "<packaging>jar</packaging>" to the child POM.

Upvotes: 2

Views: 4232

Answers (2)

Jk1
Jk1

Reputation: 11463

You could try to change a goal for the source plugin from jar to jar-no-fork. With source:jar goal as part of the lifecycle, Maven will re-run all of the goals bound to generate-sources and its predecessors. My assumption is that there is a clean executed somewhere during that loop, erasing the main jar file. In contrast, jar-no-fork will not run the bound goals again.

Plugin configuration should therefore look like

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-source-plugin</artifactId>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>jar-no-fork</goal>
         </goals>
      </execution>
   </executions>
</plugin>

Upvotes: 1

EdH
EdH

Reputation: 5003

My guess is it's trying to do that in the parentPom. I would not define the common plugins in your parentPom. In your parentPom, I would define the plugins (with their versions) in the pluginManagement section of the POM (not the plugins section). Then, in each child, state which plugins are used (without the version in the declaration). This will provide more control.

Upvotes: 2

Related Questions