Skip to content

Instantly share code, notes, and snippets.

@vkroz
Last active October 4, 2019 21:30
Show Gist options
  • Save vkroz/874872f8153eec918673d149af349d31 to your computer and use it in GitHub Desktop.
Save vkroz/874872f8153eec918673d149af349d31 to your computer and use it in GitHub Desktop.
Build Tools

Maven

Install dependency plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <configuration>
        <outputDirectory>
            ${project.build.directory}/lib
        </outputDirectory>
    </configuration>
</plugin>

Create classpath for target

mvn dependency:build-classpath

Collect all the dependent JARs for a project

mvn dependency:copy-dependencies

Download javadocs and sources for dependencies

mvn dependency:resolve -Dclassifier=javadoc
mvn dependency:resolve -Dclassifier=sources

or

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

Generate sources and javadocs

mvn source:jar
mvn javadoc:jar

To include in build process (package phase): http://maven.apache.org/plugins/maven-javadoc-plugin/usage.html

Print a dependencies tree

mvn dependency:tree -Dverbose
mvn dependency:tree -Dverbose -Dincludes=org.slf4j 

Print effective (actual) POM file

To see what POM is actually executed by maven

mvn help:effective-pom

Hosting Maven repository on Amazon S3

http://blog.brickcitylabs.com/2012/02/hosting-maven-repository-on-amazons-s3.html https://github.com/spring-projects/aws-maven

Skip running the tests

mvn install -DskipTests

Skip compiling the tests

mvn install -Dmaven.test.skip=true

Gradle

Get started

Basic commands

  • New project
gradle init
  • List available tasks
gradlew tasks
  • Build skipping tests
gradlew build -x test

Managing dependencies

  • Transitive dependencies
  # View all of them
  ./gradlew :dependencies
  
  # Analyze dependency 'commons-codec'
  gradle -q dependencyInsight --dependency commons-codec
  gradle -q dependencyInsight --dependency commons-codec --configuration compile   # other configurations: runtime, compileTest etc
  • Exclude transitive dependency from build

For example, here we exclude 'org.slf4j:slf4j-log4j12' from classpath to enable log4j2

dependencies {

    compile('org.apache.spark:spark-core_2.12:2.4.1') {
        exclude group: "org.slf4j", module: "slf4j-log4j12"
    }
    compile('org.apache.spark:spark-sql_2.12:2.4.1') {
        exclude group: "org.slf4j", module: "slf4j-log4j12"
    }
    ...
}
sbt 'set test in assembly := {}' clean
sbt 'set test in assembly := {}' clean publishLocal publishM2
sbt 'set test in assembly := {}' assembly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment