How to solve maven provided scope issue - java

I'm building a custom sonar plugin which is a maven project.
Sonar asks to mention it's required sonar-plugin-api dependency as scope provided. I think it's okay because it will run inside sonar container which will have this jar.
In my use case I want to add additional dependency of httpclient. If I add it under default scope, it refuses to build, throwing below error:
[ERROR] This dependency must be declared with scope <provided>: commons-logging:commons-logging:jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.364 s
[INFO] Finished at: 2019-03-05T13:52:22+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin:1.18.0.372:check (default-check) on project myPlugin: Unsupported dependencies
If I change the scope of httpclient to provided, it will build but will not work in sonar as it does not have this jar in its env.
All the dependencies in httpclient, including commons-logging is mentioned as scope - compile.
This is what my current pom looks like:
<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>
<groupId>com.plugin.sonar</groupId>
<artifactId>myPlugin</artifactId>
<!-- this is important for sonar-packaging-maven-plugin -->
<packaging>sonar-plugin</packaging>
<version>1.0</version>
<name>myPlugin</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<!-- minimal version of SonarQube to support. Note that the groupId was "org.codehaus.sonar" before version 5.2 -->
<version>6.7</version>
<!-- mandatory scope -->
<scope>provided</scope>
</dependency>
<!-- facing problem after adding this dependency-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.18.0.372</version>
<extensions>true</extensions>
<configuration>
<pluginKey>MyCustomPlugin</pluginKey>
<pluginClass>com.plugin.sonar.MyCustomPlugin</pluginClass>
<pluginDescription>Sonar plugin of Test</pluginDescription>
</configuration>
</plugin>
</plugins>
</build>
</project>
Any suggestions, how to solve it?
Thank You

The Sonar Maven plugin contains a check that disallows commons-logging and LOG4J because SonarQube supports only SLF4J.
So what you can do is switch to SLF4J and exclude commons-logging from the httpclient dependency:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.26</version>
</dependency>

Add an entry in the <dependencyManagement> section to manage commons-logging to provided, i.e.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>...</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
For the version: Use the one you find in your dependency:list at the moment.

Related

Unable to import any javax-servlet in Maven project in Netbeans

I am making a Maven project it is my first time with Maven. I'm using Netbeans and Tomcat server and I am not able to import any javax.servlet e.g. import javax.servlet.RequestDispatcher; etc. It looks like that:
There is info: javax.servlet does not exist and a solution proposed by Netbeans is for example: "Search Dependency at Maven Repository for javax.servlet.RequestDispatcher. When I click it then there is a pop-up window without anything to do:
I have the pom.xml file located in C://pathToNetbeansProjects/myProject/pom.xml
and I added a dependency for javax-servlet now my pom.xml looks like this:
<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>
<groupId>org.glassfish.jersey.archetypes</groupId>
<artifactId>ParkingSystem</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ParkingSystem</name>
<build>
<finalName>ParkingSystem</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<jersey.version>2.27</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
I have no more ideas if I am doing something wrong with my pom.xml or maybe I need to do something in Netbeans to make it work. But I don't know really what.
The problem is 99% caused by a different import done by Maven on that library.
Maven imports your libs following a hierarchical manner, so probably there's some lib that you have imported that contains the javax.servlet, but it's not the version that you need.
First I suggest you to looking for which one is doing that for resolving the conflict by looking into maven hierarchy, you can achieve this with console command mvn dependency:tree -Dverbose ( look here for an example).
Then you can omit the unwanted libraries by a specific maven command inside your library:
<dependency>
....
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
This is an explanation useful for understanding "why" is happening this, so you can understand it.
Btw a quick fix, that you can try as first instance, is moving the import you wanted
javax.servlet as first element of your pom.
Force update your maven project or run
mvn clean install
on your project's directory to download all dependency of pom.xml. Build your project then and javax-servlet will be available.

AWS SDK NoClassDefFoundError

I am currently trying to use the AWS SDK (specifically the s3 SDK) in my project but keep getting the exception
java.lang.NoClassDefFoundError:com/amazonaws/services/s3/AmazonS3ClientBuilder
I have imported the SDK into my project using maven as shown in the SDK documentation here. The code that I am running that causes this to occur is
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_1).build();
I suspected the issue may have been occurring due to a conflict in Jackson versions between the version required by the AWS SDK and the version I was importing myself for use else where in the project although changing this does not seem to have resolved the issue. I will include my POM.xml file below.
Thanks in advance.
<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>
<groupId>com.projectname.restservice</groupId>
<artifactId>ProjectName</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProjectName</name>
<build>
<finalName>ProjectName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.16</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.22</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<!--Removed due to possible conflict with AWS SDK?-->
<!--<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>
Output of: mvn dependency:tree -Dverbose -Dincludes=com.amazonaws
com.trailfinder.restservice:TrailFinderRestService:war:1.0-SNAPSHOT
[INFO] \- com.amazonaws:aws-java-sdk-s3:jar:1.11.22:compile
[INFO] +- com.amazonaws:aws-java-sdk-kms:jar:1.11.22:compile
[INFO] | \- (com.amazonaws:aws-java-sdk-core:jar:1.11.22:compile - omitted for duplicate)
[INFO] \- com.amazonaws:aws-java-sdk-core:jar:1.11.22:compile
I think, I've found a solution / workaround to this issue. Thanks to suggestions from #DaveMaple I tried building the app through the command line and deploying the .war manually which seems to have worked.
According to this question IntelliJ IDEA uses its own build process and not Mavens. This leads me to believe that the issue was with IntelliJ's build process and nothing to do with AWS SDK or Maven. To work around this issue I configured IntelliJ to not use its own build process but instead to use Maven and then to deploy the resulting .war. Explanation on how to do this can be found here.

set up an application with a database - tapestry-hibernate fail

I'm trying to set up an pom.xml for my web app to connect with database. The problem occurs, when I change <artifactId>tapestry-core</artifactId> to <artifactId>tapestry-hibernate</artifactId>.
Here is output when I try to build:
The POM for org.apache.tapestry:tapestry-hibernate:jar:5.4-beta-24 is missing, no dependency information available
The POM for unknown.binary:hibernate-jpa-2.1-api-1.0.0.Final:jar:SNAPSHOT is missing, no dependency information available
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.177s
Finished at: Mon Mar 30 20:18:00 CEST 2015
Final Memory: 6M/15M
------------------------------------------------------------------------
Failed to execute goal on project TapestryApp: Could not resolve dependencies for project com.rile:TapestryApp:war:1.0-SNAPSHOT: Failure to find org.apache.tapestry:tapestry-hibernate:jar:5.4-beta-24 in https://repository.apache.org/content/groups/staging/ was cached in the local repository, resolution will not be reattempted until the update interval of apache-staging has elapsed or updates are forced -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I'm using latest version of NetBeans IDE.
Here is full pom.xml file:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rile</groupId>
<artifactId>TapestryApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>TapestryApp</name>
<dependencies>
<!-- To set up an application with a database, change the artifactId below to
tapestry-hibernate, and add a dependency on your JDBC driver. You'll also
need to add Hibernate configuration files, such as hibernate.cfg.xml. -->
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<!-- Include the Log4j implementation for the SLF4J logging framework -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-release-version}</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
-->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<!-- Uncomment this to add support resource minification and runtime compilation -->
<!--
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-yuicompressor</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
-->
<!-- Uncomment this to add support for file uploads: -->
<!--
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
-->
<!-- A dependency on either JUnit or TestNG is required, or the surefire plugin (which runs the tests)
will fail, preventing Maven from packaging the WAR. Tapestry includes a large number
of testing facilities designed for use with TestNG (http://testng.org/), so it's recommended. -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng-release-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>${easymock-release-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-test</artifactId>
<version>${tapestry-release-version}</version>
<scope>test</scope>
</dependency>
<!-- Provided by the servlet container, but sometimes referenced in the application
code. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-release-version}</version>
<scope>provided</scope>
</dependency>
<!-- Provide dependency to the Tapestry javadoc taglet which replaces the Maven component report -->
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-javadoc</artifactId>
<version>${tapestry-release-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>hibernate-jpa-2.1-api-1.0.0.Final</artifactId>
<version>SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>TapestryApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<systemPropertyVariables>
<tapestry.execution-mode>Qa</tapestry.execution-mode>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- Run the application using "mvn jetty:run" -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.16</version>
<configuration>
<!-- Log to the console. -->
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<!-- This doesn't do anything for Jetty, but is a workaround for a Maven bug
that prevents the requestLog from being set. -->
<append>true</append>
</requestLog>
<systemProperties>
<systemProperty>
<name>tapestry.execution-mode</name>
<value>development</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<reporting/>
<repositories>
<!-- This repository is only needed when the Tapestry version is a preview release, rather
than a final release. -->
<repository>
<id>apache-staging</id>
<url>https://repository.apache.org/content/groups/staging/</url>
</repository>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<properties>
<tapestry-release-version>5.4-beta-24</tapestry-release-version>
<servlet-api-release-version>2.5</servlet-api-release-version>
<testng-release-version>6.5.2</testng-release-version>
<easymock-release-version>3.0</easymock-release-version>
<slf4j-release-version>1.7.7</slf4j-release-version>
</properties>
</project>
This version of tapestry-hibernate is not available in the maven central repository neither in Apache staging repository (you refer to it in your POM file).
If you want to go with the beta version then I suggest you to take the latest available (for example this one).
EDIT:
in the end of your POM file you have a property:
<tapestry-release-version>5.4-beta-24</tapestry-release-version>
change it to:
<tapestry-release-version>5.4-beta-28</tapestry-release-version>
EDIT2:
BTW, you define the following dependency twice:
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
which does no harm at the moment but you'd better clean it up.

How to exclude a dependency from parent's project in Maven?

For example, I have 2 Maven projects. One is "project-parent". The other is "project-child". Obviously, "project-child" is the sub project of "project-parent".
"project-parent" has a dependency of log4j. But I want to exclude it from the "project-child". Is there a way?
You might say I should move log4j from "project-parent" to "project-child". That is totally correct. But the assumption is I CANNOT modify "project-parent"'s POM.
Thanks in advance.
I think in Maven2 there is no way to achieve this, because this is what POM inheritance is for
. However there is one trick that I can think of:
Assume you have the right to upload artifact to your internal artifact repository. You may create an empty JAR, deploy it as log4j:log4j, with a obviously abnormal version (e.g. log4j:log4j:9999 ). Add such dependency in your project-child. Then it will override the dependency of parent to depends on a in-fact-empty JAR.
I don't know of a way of actually excluding a dependency, but you can exclude it from the target distribution, but it's a bit of a hack. You need to change the scope of the dependency to something that you can exclude in the final distribution.
So, say that my parent had a dependency on junit 4.8, in my pom you say:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>provided</scope>
</dependency>
So we're changing the scope to provided. For an explanation of how this works, see my answer to NoClassDefFoundError: org/junit/AfterClass during annotation processing. Unfortunately, this doesn't affect the build, but when you're copying the dependencies for the final distribution, you can use the excludeScope configuration element to not copy the dependency into the final distribution:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
I have met the same question just like you.
In my project, let call the parent pom is parent.pom. parent defined the log4j, slf4j like this:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
child project invoke some dependency in child.pom. But I don't want the log4j-1.2.x dependency and want to increase the version of slf4j.
So. I add the dependency of parent
<dependency>
<groupId>parent</groupId>
<artifactId>myartifactId</artifactId>
<version>${my parent version}</version>
</dependency>
and use exclusions to remove the log4j
<dependency>
<groupId>parent</groupId>
<artifactId>myartifactId</artifactId>
<version>${my parent version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
and explicitly add the slf4j and log4j2's dependency in child pom
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.4</version>
</dependency>
then use mvn dependency:tree to show the dependency list, still see the log4j
[INFO] +- org.apache.kafka:kafka_2.10:jar:0.8.2.0:compile
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | +- org.scala-lang:scala-library:jar:2.10.4:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] | | +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] | | +- log4j:log4j:jar:1.2.17:compile
well, let's add the exclusions on that dependency...remove this guy.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.10.1.1</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
then run the command again to check the dependency list. OK! clear~
Hope that can help you :>
If I understand the question, what you need is something like the following. It pulls in a dependency and excludes that dependency from adding to its dependency list. Often this is used if you want to inject a newer version of a package instead of the one referenced in the other package.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
...
</exclusions>
...
If you are instead talking about a <parent> relationship then I'm not sure there is a way to do this. Can you switch from being a <parent> to a <dependency>?
One hacky way to accomplish this is to specify the dependency in project-child but with 'test' scope (or whatever lightest-weight scope is available). This will "hide" the scope specified in project-parent so that it is available only to test code, and unavailable to non-test code at both compile and runtime.
I came across this bug-feature mostly by mistake. In my case, my project-child had a project-sibling with a 'compile' scope dependency, while project-parent had the same dependency specified (actually inherited from a grandparent) with 'provided' scope. project-child was an executable however that depended on project-sibling, and so a NoClassDefFoundError was thrown at runtime from project-sibling since project-child's runtime classpath was being used, which didn't include the 'provided' dependency. I fixed this by moving the 'compile' dependency from project-sibling to project-parent so that the 'compile' would "hide" the 'provided'.
I have managed to exclude a transient dependency from a parent pom. By re-importing it in <dependencymanagement> and then setting exclusion por the dependency I wanted out. like this eg.:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
find out actual base package for your unwanted dependency
mvn dependency:tree
Analyse this output and find out actual base package for your unwanted dependency
now add dependency of base package again in child pom and use exclude tag
<dependency>
<groupId>base group id</groupId>
<artifactId>base artifact id</artifactId>
<version>version</version>
<exclusions>
<exclusion>
<groupId>your unwanted dependency group id</groupId>
<artifactId>your unwanted dependency artifact id</artifactId>
</exclusion>
</exclusions>
</dependency>
check again
mvn dependency:tree
unwanted dependency should be removed.

Unable to update snapshots or run the install goal with Maven

Does anyone have an idea how to resolve this Maven error? I get the following when I attempt to update my project's snapshots:
Build errors for my-projects-name;
org.apache.maven.lifecycle.LifecycleExecutionException:
Internal error in the plugin manager
executing goal
'org.apache.maven.plugins:maven-dependency-plugin:2.0:unpack':
Mojo execution failed.
And then when I try running "mvn install":
[INFO] [assembly:single {execution:default}] [INFO]
---------------------------------------------------------
[ERROR] BUILD ERROR [INFO]
---------------------------------------------------------
[INFO] Error reading assemblies: No assembly descriptors found.
I'm running Maven 2.1.0. Can anyone shed some light as to why it's balking at me? Other team members are able to perform the above actions with the exact same copy of the code from SVN.
Thanks!
Edit: Here's the POM:
<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>
<parent>
<groupId>com.company.group</groupId>
<artifactId>the-project-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.company.group.project</groupId>
<artifactId>project-root</artifactId>
<packaging>pom</packaging>
<name>Project Name</name>
<version>1.0.2-SNAPSHOT</version>
<description>This artifact contains the common settings for the Project.</description>
<url>http://maven.dev.companyName.com/sites/projectGroup/project</url>
<scm>
<connection>scm:svn:https://sourceforge.companyname.com/svn/repos/group/tags/projGroup/my-project-name</connection>
<developerConnection>scm:svn:https://sourceforge.companyname.com/svn/repos/group/tags/projGroup/my-project-name</developerConnection>
</scm>
<modules>
<module>module-1</module>
<module>module-2</module>
<module>module-3</module>
<module>module-4</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sourceforge.jtds.jdbc</groupId>
<artifactId>jtds</artifactId>
<version>1.2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<!-- I cut most dependencies for brevity -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-5</version>
<inherited>false</inherited>
<configuration>
<preparationGoals>clean install</preparationGoals>
<tagBase>https://sourceforge.companyname.com/svn/repos/projects/tags/projGroup/my-project-name</tagBase>
</configuration>
</plugin>
</plugins>
</build>
</project>
You have no assembly plugin configuration shown in the pom you pasted. Perhaps it's in the parent? If there's no config then the assembly plugin will complain because you haven't configured it with a descriptor that tells it what to do. run mvn help:effective-pom and then paste those results (make sure to scrub any passwords) so I can see your full pom after inheritence.
I finally got it to run the install goal by downgrading Maven to 2.0.9.
EDIT:
I tried executing mvn clean install and mvn clean install assembly:assembly using Maven 2.1.0 and it duplicated the above error: > "No Assembly descriptors found."
It still works with Maven 2.0.9. I'm wholly convinced that at minimum something has changed between versions which is causing this this discrepancy...
EDIT:
From what I've been able to find out, it appears there's likely some kind of version conflict between Maven 2.1.0 and the version of this plugin we use:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-5</version>

Categories