Maven plugin external dependencies are not resolved

Viewed 1028

I am writing a maven plugin using Mojo classes. The plugin requires a dependency called jcifs and included it in the pom.xml of the plugin. I am able build the plugin and it is deployed into my local repository. I can find the jar file and pom.xml in my local repository.

When I use this plugin in another project in my local system, when executing the plugin goal, I am getting an exception saying the class not found. But the class is coming from the jcifs jar and it is included as part of the dependency for my plugin.

I am not able to figure out what I am missing here. Any help is appreciated

Following is the plugin pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.mayuran19.maven.plugin</groupId>
<artifactId>LocalToRemoteRepo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>localtoremoterepo-maven-plugin</name>

<properties>
    <mavenVersion>3.2.1</mavenVersion>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.5.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>${mavenVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>1.3.17</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.3</version>
                <executions>
                    <execution>
                        <id>default-descriptor</id>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Following show is the pom.xml of the project that use this plugin

<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.mayuran19.maven.plugin</groupId>
<artifactId>LocalToRemoteRepo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>localtoremoterepo-maven-plugin Test</name>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-core</artifactId>
        <version>4.3.4.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.shared</groupId>
        <artifactId>maven-dependency-tree</artifactId>
        <version>3.0.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>1.3.17</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>com.mayuran19.maven.plugin</groupId>
            <artifactId>LocalToRemoteRepo</artifactId>
            <version>1.0-SNAPSHOT</version>
            <configuration>
                <localRepoDir>C:/Users/smayuran.SITBCS/.m2/repository</localRepoDir>
                <remoteRepoDir>smb://192.168.9.196/internal</remoteRepoDir>
                <username>G3App</username>
                <password>P@ssword$1</password>
            </configuration>
        </plugin>
    </plugins>
</build>

Error I am getting is class not found exception from the library jcifs

1 Answers

You can do this way, if you want:

**Step 1:**Download the jar file to you local machine

**Step 2:**Moving you jar to you maven repo:Run as shown bellow

Example:

<dependency>
  <groupId>org.mock-server</groupId>
  <artifactId>mockserver-netty</artifactId>
 <version>3.10.1</version>
</dependency>

mvn install:install-file -Dfile=C:\Users\username\Desktop\mockserver-netty-3.10.1.jar -DgroupId=org.mock-server -DartifactId=mockserver-netty -Dversion=3.10.1 -Dpackaging=jar

Related