Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Sunday, 5 June 2016

Maven Release Plugin

Please add following block in your maven settings.xml:
<servers>
<server>
<id>scm-server</id>
<username>YOUR_USER_NAME</username>
<password>YOUR_ENCRYPTED_PASSWORD</password>
</server>
</servers>

Please note the released project pom doesn't contain SNAPSHOT dependencies.
To use it locally,1. mvn release:clean
2. mvn release:prepare

3. mvn release:perform

<plugin>
       <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
 <version>2.5.3</version>
<configuration>
<connectionType>connection</connectionType>
<goals>deploy</goals>
<autoversionsubmodules>true</autoversionsubmodules>
</configuration>
<executions>
    <execution>
<id>default</id>
<goals>
<goal>perform</goal>
        </goals>
<configuration>
     <pomFileName>com.td.dpu.common/pom.xml</pomFileName>
</configuration>
    </execution>
       </executions>
</plugin>


Setup Maven setting.xml for Nesus Access

  1. Download the settings.xml file from the nexus repo
    1. Create a blank settings.xml file in the C:\Users\{loginid}\.m2 folder.
  2. Encrypt your domain / AD password
    1. Create an encrypted master password by executing
    2. $ mvn --encrypt-master-password
      Master password:(type your password here) on the command line.
      Your password should look like {jOhnSnoWLives+jiuyrewhsidufsdjfks+9EF1iFQyJQ=}
    3. Update this password in the settings-security.xml file in the C:\Users\Redirection\{loginid}\.m2 folder. Make sure you are updating within the 'Redirection' folder and not elsewhere.
    4. Create an encrypted password (different from the master password) by executing
    5. $ mvn --encrypt-password
      Password: (type your password here) on the command line.
    6. Update the settings.xml file. Paste in your user id and generated non-master password in the servers section at the bottom of the file.
      More Details:  http://maven.apache.org/guides/mini/guide-encryption.html
  3. Install VeriSign CA certificate to the default truststore
    1. Download verisignClass3secureServerCA 
    2. Add the cert into your JVM - $JRE_HOME/lib/security/cacerts using the keyTool.exe utility
    3. Run below command as Admin
                    C:\Program Files\Java\jdk1.8.0_65\jre\lib\security>..\..\bin\keytool.exe -import
                    -trustcacerts -alias verisignClass3secureServerCA -file verisignClass3secureServerCA.cer -keystore cacerts
                    Enter keystore password:

                    Certificate was added to keystore

Wednesday, 9 March 2016

Fetching AppInfo from Manifest

Sometimes, we want to dynamically fetch App info without hardcoding them.
We can get these info from manifest.

Add below plugin in the parent pom.xml
In the child pom.xml, setup below
<artifactId>com.test.app</artifactId>
<name>AppName</name>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
     <manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
     </manifest>
<manifestEntries>
<Implementation-Build>${maven.build.timestamp}</Implementation-Build>
<APP-ID>${artifactId}</APP-ID>
<APP-NAME>${name}</APP-NAME>
<APP-VERSION>${version}</APP-VERSION>
        </manifestEntries>
</archive>
</configuration>
</plugin>

def getAppInfo: (String, String) = {

    val p = getClass.getPackage
    val appName = Option(p.getImplementationTitle)
                  .getOrElse("MyApp")
    val version = Option(p.getImplementationVersion)
                  .getOrElse("SNAPSHOT")
    (appName, version)
  }

Saturday, 2 January 2016

scalatest-maven-plugin issue

When use scalatest-maven-plugin, you may encounter below error:

[INFO] --- scalatest-maven-plugin:1.0:test (test) @ pos3-adapter ---
Exception in thread "ScalaTest-main" java.lang.IllegalArgumentException: Use of A was deprecated in ScalaTest 1.0 and removed in 1.5. Please check the Scaladoc documentation of org.scalatest.Runner for information on valid Reporter config parameters.
  at org.scalatest.tools.Runner$.parseConfigSet(Runner.scala:1470)
  at org.scalatest.tools.Runner$.buildFileReporterConfigurationList$1(Runner.scala:1700)
  at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1704)
  at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:923)
  at org.scalatest.tools.Runner$.main(Runner.scala:860)
  at org.scalatest.tools.Runner.main(Runner.scala)

The ScalaTest Maven plugin contains two "mojos". The test mojo is for "mvn test" commands, and the reporter mojo is for "mvn site" commands.

Solution:


Disable reporter mojo by removing all reporter relevant setting in the <configuration> tag

Reference:

Tuesday, 15 December 2015

"provided" vs "compile" in Maven

Sometimes you may encounter below error, when run a simple Spark App built by Maven in IntelliJ IDEA.

Error: ClassNotFoundException: org.apache.spark.SparkConf

Please check the dependency scope of Spark in pom.xml.
Change the scope from "provided" to "compile". Then the problem is solved.

"provided" vs "compile" in Maven

  • compile scope is the default scope, and available in all classpaths.
  • provided scope is only available on the compilation and test classpath, and dependencies are not transitive. 
  • provided dependencies are not packaged

Reference:

http://stackoverflow.com/questions/6646959/difference-between-maven-scope-compile-and-provided-for-jar-packaging

Friday, 31 October 2014

Maven Usage

Maven is used for compiling and managing dependencies.
The pom.xml file is the XML representation of the project and thus contains all metadata pertaining to the project.

1. Generate a Maven Java project

$ mvn archetype:generate

you will have to enter the Maven "project co-ordinates" such as groupId, artifactId, version, and package.
groupId: com.companyname
artifactId: project name
version: 1.0-SNAPSHOT
packaging: jar

2. Compile a project. Navigate to pom.xml folder.

$ mvn compile
It will download dependencies, then It will trigger the Java compiler associated with the project.

3. $ mvn test

Triggers Maven to run the tests present in the .../src/test folder

4. Download sources of dependencies, check the default settings of maven
$ mvn -X
Load sources

$mvn dependency:sources

5. Run an individual module and skip the tests


$ mvn clean install -rf :ethoca-ejb -DskipTests


6.  build the JAR
mvn clean package

run the JAR

mvn exec:java -Dexec.mainClass="SimpleApp"





Thursday, 14 August 2014

Maven Assembly Plugin Usage


An "assembly" is a group of files, directories, and dependencies that are assembled into an archive format and distributed.
The Assembly Plugin provides a descriptor format which allows you to define an arbitrary assembly of files and directories from a project. 
The main goal in the assembly plugin is the single goal. It is used to create all assemblies. All goals except assembly:single have been deprecated.

Add Assembly plugin in pom.xml
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/descriptor.xml
                            </descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>assembly</id>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    </build>


A descriptor.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>binary</id>
    <formats>
        <format>tar.gz</format>
    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>
    <baseDirectory>${project.artifactId}-${project.version}</baseDirectory>

    <dependencySets>
         <dependencySet>
            <outputDirectory>/lib</outputDirectory>
           <includes>
                 <include>*:exernallib*</include>
           </includes>
         </dependencySet>
    </dependencySets>

   <componentDescriptors>
         <componentDescriptor>path/component.xml</componentDescriptor>
   </componentDescriptors>

    <fileSets>
        <fileSet>
            <directory>
                src/main/resources/lib
            </directory>
            <outputDirectory>${project.artifactId}-workflow/lib</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>
                src/main/resources/scripts/sqoop
            </directory>
            <includes>
                <include>sqoop_param.txt</include>
            </includes>
            <outputDirectory>${project.artifactId}-workflow/</outputDirectory>
            <filtered>true</filtered>
            <fileMode>0744</fileMode>
        </fileSet>

        <fileSet>
            <directory>
                src/main/resources/job/
            </directory>
            <includes>
                <include>job.properties</include>
            </includes>
            <outputDirectory>.</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

Reference:
http://maven.apache.org/plugins/maven-assembly-plugin/
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/index.html

Friday, 20 June 2014

Set JDK 1.6 in IntelliJ IDE

1.
Install JDK1.6 (/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/)
Right Click "selected Project" -> Open Module Settings -> Project -> Project SDK->JDK1.6

In pom.xml, add maven-compiler-plugin
<artifactId>yourproject</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<version>0.0.1-SNAPSHOT</version>


2. Generate .jar by using Maven from IntelliJ

Maven Projects->package->Right click "Run Maven Build"
Find the jar file from "~/IdeaProjects/projectname/target/"