Custom Maven packaging, transitive dependencies aren't included - maven-3

I'm playing around with a custom Maven 3 packaging plugin for some non-java artifacts, and having an issue getting transitive dependencies to work. I've got three projects defined, model, model-impl, and cli, with dependencies like this:
cli
model-impl
model
My custom lifecycle plugins are being called in each project, and I can successfully build model and model-impl. For each of those projects, the expected artifacts are being stored in my local repository. cli however is failing because I don't get model as a dependency in my Mojo. I'm not completely sure that this is a problem in my code though, because even using mvn dependency:dependency-tree doesn't show the full dependency hierarchy:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.corp.nodes:myproj-cli >-----------------------
[INFO] Building myproj Test 1.0.0-SNAPSHOT
[INFO] --------------------------------[ myproj ]--------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # myproj-cli ---
[INFO] com.corp.nodes:myproj-cli:myproj:1.0.0-SNAPSHOT
[INFO] \- com.corp.:myproj-model-impl:myproj:1.0.0-SNAPSHOT:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Here I would have expected that I see a tree with three levels for each of the projects.
Here's the components.xml defined in my custom plugin:
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>myproj</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<initialize>com.corp.maven:myproj-plugin:unpackageDependencies</initialize>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>com.corp.maven:myproj-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>com.corp.maven:myproj-plugin:package</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>myproj</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>myproj</type>
<extension>myproj</extension>
<packaging>myproj</packaging>
<addedToClasspath>true</addedToClasspath>
<includesDependencies>true</includesDependencies>
</configuration>
</component>
</components>
</component-set>
All of the project POMs have their packaging set to myproj, and all of the dependencies have their type set to myproj. Here's the pom for the cli project:
<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.corp.arthur.nodes</groupId>
<artifactId>myproj-cli</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>myproj</packaging>
<name>myproj Test</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.corp.arthur</groupId>
<artifactId>myproj-model-impl</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>myproj</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.corp.maven</groupId>
<artifactId>myproj-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
The POM for the impl project looks similar. Any idea's what I'm missing?

Finally figured out what was going on by tracing through the source for the DefaultDependencyCollector class. Turns out I needed to set includesDependencies in my components.xml to false. What was happening is the dependency collector saw that flag was true, meaning the dependencies were included in the artifact, and so didn't recurse through them. With it set to false, it does recurse, and I get the expected behavior.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.corp.nodes:myproj-cli >------------------
[INFO] Building myproj Test: CLI Node 1.0.0-SNAPSHOT
[INFO] --------------------------------[ myproj ]--------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # myproj-cli ---
[INFO] com.corp.nodes:myproj-cli:myproj:1.0.0-SNAPSHOT
[INFO] \- com.corp:myproj-model-impl:myproj:1.0.0-SNAPSHOT:compile
[INFO] \- com.corp:myproj-model:myproj:1.0.0-SNAPSHOT:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

I've been struggling with a similar problem while trying to include my android lib via maven to my another project. My research has shown that library's pom file isn't included in maven library for some cases like mine was - I had an .aar file. Hence, your project build system doesn't know anything about these transitive dependencies. The solution for me was to manually point them in in my Gradle file. You can familiarize with this more concretely in this topic.

Related

Jenkins not able to run soapUI test: No test to run

I am running SoapUI test from Jenkins.
I have placed my soapui-project.xml file placed in same directory where my pom.xml is placed which is in master in bitbucket. Jenkins is able to pick all changes in my pom.xml. but not running tests.
Jenkin log says "no test to run"
I tried adding source and placing my soapui-project.xml file in src/main/resources keeping below properties.
<sourceDirectory>src/main/resources</sourceDirectory>
<testSourceDirectory>src/main/resources</testSourceDirectory>
but behavior not changed.
my pom.xml is as below
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Test soapui</name>
<groupId>RestCountriesInfo</groupId>
<artifactId>com.example.soapuitests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>SOAPUITesting</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<!-- <sourceDirectory>src</sourceDirectory>
<testSourceDirectory>src/main/resources</testSourceDirectory>
-->
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.5.0</version>
<dependencies>
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>forms</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>RestCountriesInfo</id>
<configuration>
<projectFile>RestCountriesInfo-soapui-project.xml</projectFile>
<outputFolder>src/main/resources/report</outputFolder>
<testSuite>DEV</testSuite>
<junitReport>true</junitReport>
<exportAll>true</exportAll>
<printReport>true</printReport>
<testFailIgnore>true</testFailIgnore>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And here are Jenkins logs
Posting build status of INPROGRESS to SWC Bitbucket for commit id [d95035dda15d279d5622478d8dbd178591e1f66a] and ref 'refs/heads/master'
Failed to post build status, additional information: timeout
[API_TEST] $ /opt/maven/bin/mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< RestCountriesInfo:com.example.soapuitests >--------------
[INFO] Building Test soapui 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # com.example.soapuitests ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # com.example.soapuitests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # com.example.soapuitests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # com.example.soapuitests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/jenkins/workspace/Feature/Dev/API_TEST/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # com.example.soapuitests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # com.example.soapuitests ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.454 s
[INFO] Finished at: 2022-11-29T12:47:34+11:00
[INFO] ------------------------------------------------------------------------
Any idea why Jenkins not able to execute my tests.
Notice in your log output that the soapui-maven-plugin never got run.
You have two options:
In Jenkins you can specify the target phase: com.smartbear.soapui:soapui-maven-plugin:5.5.0:test, as per official documentation. But as you can see this contains the plugin version in the command, which is probably undesirable.
You can add a <phase> that you want to run the soapui plugin in; probably test. This goes in your <configuration> block. Note that <goal> and <phase> are not the same thing; they each configure something different, even thought they might have the same target. More information is available in official documentation.
As a side note, the <packaging> for this project is not jar - there is no compile phase. It is just pom.

No plugin found for prefix 'docker' in the current project and in the plugin groups

deploy Spring Cloud project with docker, some code in the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
when i execute the command: mvn package docker:build, it throws the above errors:
Downloaded: http://3.2.4.2:8888/repository/maven-public/org/apache/maven/plugins/maven-metadata.xml (14 KB at 5.7 KB/sec)
Downloaded: http://3.2.4.2:8888/repository/maven-public/org/codehaus/mojo/maven-metadata.xml (21 KB at 7.3 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] eureka-server ...................................... SUCCESS [ 26.279 s]
[INFO] service-1 ......................................... SUCCESS [ 14.649 s]
[INFO] demo1 ........................................... FAILURE [ 2.850 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.535 s
[INFO] Finished at: 2017-11-15T14:28:05+08:00
[INFO] Final Memory: 47M/532M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'docker' in the current project
and in the plugin groups [org.sonatype.plugins, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/../Repository), nexus (http://3.2.4.2:8888/repository/maven-public/)]
how to solve it?
add the below code to your maven conf/setting.xml:
<pluginGroups>
<pluginGroup>com.spotify</pluginGroup>
</pluginGroups>
if you want to get more detail, pls refer to https://github.com/spotify/docker-maven-plugin/issues/322
If you are using dockerfile maven plugin, you need to change docker:build to
dockerfile:build and docker:push to dockerfile:push
For me worked in a different way, if you follow the maven plugin pattern {prefix}-maven-plugin... which in this case is dockerfile-maven-plugin, you should be able to run it with: mvn package dockerfile:build.
I'm using Maven: 3, Spring Boot 2 and Docker maven plugin 1.3.4

Jenkins : Run Multiple Dependencies Maven Project

I have 3 maven projects. Project1, Project2 & Project3.
Project3 depends on Project1 & Project2 and Project2 depends on Project1.
For this I have added this in Project2 pom.xml file
<modelVersion>4.0.0</modelVersion>
<groupId>Project2</groupId>
<artifactId>Project2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>Project1</groupId>
<artifactId>Project1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
My pom.xml for Project3 is -
<modelVersion>4.0.0</modelVersion>
<groupId>Project3</groupId>
<artifactId>Project3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>Project1</groupId>
<artifactId>Project1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>Project2</groupId>
<artifactId>Project2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
In the project 3 I have added testng.xml file to run the test. Now If I run this testng.xml file then all my test cases are running successfully.
I have included testng.xml file in the pom file below dependencies to run testng test using maven -
<build>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>Tng1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be used for compiling the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Even these tests are running when I am trying to run this using Maven Test. But when I tried to run this using jenkins then it fails and shows below error.
[WARNING] The POM for Project1:Project1:jar:0.0.1-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for Project2:Project2:jar:0.0.1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.476 s
[INFO] Finished at: 2015-08-25T15:16:56+05:30
[INFO] Final Memory: 13M/114M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Project3: Could not resolve dependencies for project Project3:Project3:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: Project1:Project1:jar:0.0.1-SNAPSHOT, Project2:Project2:jar:0.0.1-SNAPSHOT: Could not find artifact Project1:Project1:jar:0.0.1-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Please Help !!!

How to override parameters of maven-war-plugin defined in parent pom.xml?

I'm trying to build a grails project with maven. By itself, that wouldn't be so hard. But it is required that the pom.xml in my project have a certain enterprise pom as it's parent.
The parent pom has many things in it that are important in our deployment process here, but it also contains the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
<webXml>webapp/WEB-INF/web.xml</webXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
If I understand correctly, this tells maven to look for a web.xml file in webapp/WEB-INF. At this point, my project doesn't have a web.xml file, though it might later. How can I override this specification of the location of a web.xml file so that maven would:
Not look for a web.xml file at all.
Look for a web.xml file elsewhere.
As it is, after compiling and running tests, Maven reports:
Tests PASSED - view reports in target\test-reports
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[myapp] in [C:\code\workspace\myapp\myapp\target\myapp-current]
[INFO] Processing war project
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] The specified web.xml file 'C:\code\workspace\myapp\myapp\webapp\WEB-INF\web.xml' does not exist
[INFO] ------------------------------------------------------------------------
I think that it is interesting, that the command being executed is [war:war {execution: default-war}] rather than [grails:war] or something. That might be relevant, also.
My solution:
Replace
<packaging>war</packaging>
with
<packaging>grails-app</packaging>

maven antrun plugin

I have the following in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ant-plugin</artifactId>
<version>2.3</version>
<configuration>
<target>
<echo
message="hello ant, from Maven!" />
<echo>Maybe this will work?</echo>
</target>
</configuration>
</plugin>
Yet, when I run 'mvn antrun:run' I get this:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'antrun'.
[INFO] ------------------------------------------------------------------------
[INFO] Building myProject
[INFO] task-segment: [antrun:run]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: default-cli}]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Sep 24 13:33:14 PDT 2010
[INFO] Final Memory: 16M/28M
[INFO] ------------------------------------------------------------------------
How come the echo's don't show up?
TIA
Because you are supposed to use the Maven AntRun Plugin if you want to execute Ant tasks, not the Maven Ant Plugin (which is used to generate build files for Ant 1.6.2 or above from the POM). Modify your plugin configuration as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<configuration>
<target>
<echo message="hello ant, from Maven!"/>
<echo>Maybe this will work?</echo>
</target>
</configuration>
</plugin>
And invoking antrun:run will work:
$ mvn antrun:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3790798 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.5:run (default-cli) # Q3790798 ---
[INFO] Executing tasks
main:
[echo] hello ant, from Maven!
[echo] Maybe this will work?
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
Make sure maven-antrun-plugin is using a recent enough version.
An unrelated BOM in my project was locking it to 1.3, and <echo> was being ignored. After removing the BOM and specifying 1.7 for antrun, the echoes worked.

Resources