Skip to content

Maven plugin to copy certain java sources into generated sources in order to reduce undesired dependencies

License

Notifications You must be signed in to change notification settings

bytemechanics/copysource-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Copy Sources maven plugin

Latest version Quality Gate Coverage License

Maven pluguin to copy and repackage sources to reduce library dependencies

IMPORTANT NOTE: We strongly recommends to use this plugin only for libraries, for final projects if you want to build a uber-jar maven already has it's shade plugin that works perfectly

Motivation

To keep the dependency hell away from your projects its important to reduce at minimum the dependencies of each library. But at te same time this can break the code reutilization principle, to avoid this flag the solution comes by copying the source code and repackaging in order to avoid collisions. But this is only necessary when you need ONLY some specific classes, if you need the full library then you should add it as dependency.

Goals

Available goals:

  • copy-classes: Copy classes to generated-sources
  • copy-test-classes: Copy classes to generated-test-sources

Quick start

IMPORTANT NOTE: We strongly recommends to use this plugin only for libraries, for final projects if you want to build a uber-jar maven already has it's shade plugin that works perfectly

  1. Add the pluguin to your pom
    (...)
       <build>
          <plugins>
             (...)
             <plugin>
                <groupId>org.bytemechanics.maven</groupId>
                <artifactId>copysource-maven-plugin</artifactId>
                <version>X.X.X</version>
            </plugin>
            (...)
         </plugins>
    </build>
    (...)
  2. Define the execution goal "copy-classes" (the phase it's not necessary, by default uses "generate-sources")
    (...)
    <build>
       <plugins>
          (...)
          <plugin>
             <groupId>org.bytemechanics.maven</groupId>
             <artifactId>copysource-maven-plugin</artifactId>
             <version>X.X.X</version>
             <executions>
                <execution>
                   <goals>
                      <goal>copy-classes</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>		
          (...)
        </plugins>
    </build>	
    (...)
  3. Configure it with the copies that you want to do:
    (...)
    <build>
       <plugins>
          (...)
          <plugin>
             <groupId>org.bytemechanics.maven</groupId>
             <artifactId>copysource-maven-plugin</artifactId>
             <version>X.X.X</version>
             <executions>
                <execution>
                   <goals>
                      <goal>copy-classes</goal>
                   </goals>
                   <configuration>
                      <copies>
                         <copy>
                            <artifact>[source-groupId]:[source-artifactId]:[source-version]</artifact>
                            <classes>
                               <class>[cannonical-name-of-origin-source. Example:org.bytemechanics.commons.functional.LambdaUnchecker]</class>
                               (...)
                            </classes>
                            <fromPackage>[package-segment-to-replace. Example: org.bytemechanics.commons]</fromPackage>
                            <toPackage>[package-segment-to-replace. Example: org.bytemechanics.standalone.ignite.internal.commons]</toPackage>
                         </copy>
                      </copies>
                   </configuration>
                </execution>
             </executions>
          </plugin>		
          (...)
        </plugins>
    </build>	
    (...)

(Please read our Javadoc for further information)