Maven Source Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 34: Line 34:
:<br>'''Important''' Place the plugin in <tt><plugins></tt>, not in <tt><pluginManagement><plugins>...</plugins></pluginManagement></tt>, otherwise it will silently fail. For a project hierarchy, place the plugin at each level of the hierarchy where you want to publish sources.<br><br>
:<br>'''Important''' Place the plugin in <tt><plugins></tt>, not in <tt><pluginManagement><plugins>...</plugins></pluginManagement></tt>, otherwise it will silently fail. For a project hierarchy, place the plugin at each level of the hierarchy where you want to publish sources.<br><br>
</blockquote>
</blockquote>
=Running from Command Line=
<pre>
mvn source
</pre>


=Installing the source artifact in the repository post factum=
=Installing the source artifact in the repository post factum=

Revision as of 20:36, 10 January 2017

External

Internal

Generating the source jar

<build>
     <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
     </plugins>
</build>

If the "maven-source-plugin" is active, maven install will also install the source jar.


Important Place the plugin in <plugins>, not in <pluginManagement><plugins>...</plugins></pluginManagement>, otherwise it will silently fail. For a project hierarchy, place the plugin at each level of the hierarchy where you want to publish sources.


Running from Command Line

mvn source

Installing the source artifact in the repository post factum

mvn install:install-file -DgroupId=my.group -DartifactId=my-file -Dversion=1.0 \
  -Dpackaging=jar -Dclassifier=source -Dfile=./my-file-src.jar