How do you resolve dependencies across all modules in a maven plugin? - maven

I'm writing a Maven plugin that gets the resolved dependencies. It works fine for a single module project/pom, but fails on multiple module projects.
Here's a code snippet
#Mojo(
name="scan",
aggregator = true,
defaultPhase = LifecyclePhase.COMPILE,
threadSafe = true,
requiresDependencyCollection = ResolutionScope.TEST,
requiresDependencyResolution = ResolutionScope.TEST,
requiresOnline = true
)
public class MyMojo extends AbstractMojo {
#Parameter(property = "project", required = true, readonly = true)
private MavenProject project;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
#Override
public void execute() throws MojoExecutionException {
for(MavenProject p : reactorProjects) {
for(Artifact a : p.getArtifacts()) {
...consolidate artifacts
}
}
}
}
The above code will consolidate all the resolved dependencies across all the modules, but it includes some additional ones.
Here's a sample project to work with. Please download this github repo
From the modules-project main folder, please run
mvn dependency:tree -Dverbose -Dincludes=commons-logging
You should see an output like this
[INFO] ------------------------------------------------------------------------
[INFO] Building core 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # core ---
[INFO] com.github:core:jar:0.1-SNAPSHOT
[INFO] \- axis:axis:jar:1.4:compile
[INFO] +- commons-logging:commons-logging:jar:1.0.4:runtime
[INFO] \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] \- (commons-logging:commons-logging:jar:1.0.3:runtime - omitted for conflict with 1.0.4)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building web 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # web ---
[INFO] com.github:web:war:0.1-SNAPSHOT
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] \- com.github:core:jar:0.1-SNAPSHOT:compile
[INFO] \- axis:axis:jar:1.4:compile
[INFO] +- (commons-logging:commons-logging:jar:1.0.4:runtime - omitted for conflict with 1.1.1)
[INFO] \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] \- (commons-logging:commons-logging:jar:1.0.3:runtime - omitted for conflict with 1.1.1)
[INFO] ------------------------------------------------------------------------
Notice that the module/project core depends on commons-logging 1.0.4 and commons-logging 1.0.3, but 1.0.3 is omitted due to a conflict and 1.0.4 is resolved.
This means that if you were to build core on its own, you should only get commons-logging 1.0.4.
Notice that module/project web depends on conflicting versions of commons-logging as well but resolves to 1.1.1.
Now if you were to build the "entire project" (modules-project) with the "mvn package" command, you should see that modules-project/web/target/myweb/WEB-INF/lib contains all the resolved dependencies and it includes ONLY commons-logging 1.1.1.
Here's the problem with the code
In the above code, reactorProjects is instantiated with 3 MavenProject's: modules-project, core, and web.
For modules-project and web, it resolves and returns commons-logging 1.1.1. However, for the core project, it resolves and returns commons-logging 1.0.4.
I want my plugin code to know that commons-logging 1.1.1 is the dependency that the build will produce, and not commons-logging 1.0.4
Any thoughts?

You practically have all it takes in your question. The following plugin will print in the console output the artifacts of the WAR project in the reactor:
#Mojo(name = "foo", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST)
public class MyMojo extends AbstractMojo {
#Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
#Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
public void execute() throws MojoExecutionException, MojoFailureException {
MavenProject packagedProject = getWarProject(reactorProjects);
for (Artifact artifact : packagedProject.getArtifacts()) {
getLog().info(artifact.toString());
}
}
private MavenProject getWarProject(List<MavenProject> list) throws MojoExecutionException {
for (MavenProject project : list) {
if ("war".equals(project.getPackaging())) {
return project;
}
}
throw new MojoExecutionException("No WAR project found in the reactor");
}
}
What this does is that it acquires all the projects in the reactor with the injected parameter reactorProjects. Then, it loops to find which one of those is the "war" by comparing their packaging. When it is found, getArtifacts() will return all the resolved artifacts for that project.
The magic that makes it work is the aggregator = true in the MOJO definition:
Flags this Mojo to run it in a multi module way, i.e. aggregate the build with the set of projects listed as modules.
When added to core POM
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>test-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<goals>
<goal>foo</goal>
</goals>
</execution>
</executions>
</plugin>
and run with your example project, this prints in the console:
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] com.github:core:jar:0.1-SNAPSHOT:compile
[INFO] axis:axis:jar:1.4:compile
[INFO] org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] axis:axis-wsdl4j:jar:1.5.1:runtime
[INFO] commons-discovery:commons-discovery:jar:0.2:runtime
This is good enough. With that, we can go forward and, for example, compare the resolved artifacts by the current project being build and the packaged project. If we add a method
private void printConflictingArtifacts(Set<Artifact> packaged, Set<Artifact> current) {
for (Artifact a1 : current) {
for (Artifact a2 : packaged) {
if (a1.getGroupId().equals(a2.getGroupId()) &&
a1.getArtifactId().equals(a2.getArtifactId()) &&
!a1.getVersion().equals(a2.getVersion())) {
getLog().warn("Conflicting dependency: " + a2 + " will be packaged and found " + a1);
}
}
}
}
called with
printConflictingArtifacts(packagedProject.getArtifacts(), project.getArtifacts());
that compares the current artifacts with the artifacts of the packaged project, and only retain those with the same group/artifact id but different version, we can get in the console output with your example:
[WARNING] Conflicting dependency: commons-logging:commons-logging:jar:1.1.1:compile will be packaged and found commons-logging:commons-logging:jar:1.0.4:runtime
The above assumed that our final packaging module was a WAR module. We could make that more generic and let the user specify which one of the module is the target module (i.e. that will package the real delivery).
For that, we can add a parameter to our MOJO
#Parameter(property = "packagingArtifact")
private String packagingArtifact;
This parameter will be of the form groupId:artifactId and will represent the coordinates of the target module. We can then add a method getPackagingProject whose goal will be to return the MavenProject associated with those coordinates.
The configuration of the plugin inside core would be
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>test-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<goals>
<goal>foo</goal>
</goals>
<configuration>
<packagingArtifact>com.github:web</packagingArtifact>
</configuration>
</execution>
</executions>
</plugin>
And the full MOJO would be:
#Mojo(name = "foo", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.COMPILE)
public class MyMojo extends AbstractMojo {
#Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
#Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
#Parameter(property = "packagingArtifact")
private String packagingArtifact;
public void execute() throws MojoExecutionException, MojoFailureException {
MavenProject packagedProject = getPackagingProject(reactorProjects, packagingArtifact);
printConflictingArtifacts(packagedProject.getArtifacts(), project.getArtifacts());
}
private void printConflictingArtifacts(Set<Artifact> packaged, Set<Artifact> current) {
for (Artifact a1 : current) {
for (Artifact a2 : packaged) {
if (a1.getGroupId().equals(a2.getGroupId()) && a1.getArtifactId().equals(a2.getArtifactId())
&& !a1.getVersion().equals(a2.getVersion())) {
getLog().warn("Conflicting dependency: " + a2 + " will be packaged and found " + a1);
}
}
}
}
private MavenProject getPackagingProject(List<MavenProject> list, String artifact) throws MojoExecutionException {
if (artifact == null) {
return getWarProject(list);
}
String[] tokens = artifact.split(":");
for (MavenProject project : list) {
if (project.getGroupId().equals(tokens[0]) && project.getArtifactId().equals(tokens[1])) {
return project;
}
}
throw new MojoExecutionException("No " + artifact + " project found in the reactor");
}
private MavenProject getWarProject(List<MavenProject> list) throws MojoExecutionException {
for (MavenProject project : list) {
if ("war".equals(project.getPackaging())) {
return project;
}
}
throw new MojoExecutionException("No WAR project found in the reactor");
}
}
This implements the idea of above: when the user has given a target module, we use it as reference. When this parameter is not present, we default to finding a WAR in the reactor.

Related

"Dependency problems found" when `mvn clean install` a che plugin project

I downloaded the che plugin project example che-ide-server-extension. It works when mvn clean install. But when I add a dependency in
che-ide-server-extension/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
, it fails to install.
The dependency I added is
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-ui</artifactId>
</dependency>
And the error message of mvn clean install -e -X is:
...
[WARNING] Unused declared dependencies found:
[WARNING] org.eclipse.che.core:che-core-ide-ui:jar:6.16.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Plugin ServerService :: Parent pom ................. SUCCESS [ 2.174 s]
[INFO] Plugin ServerService :: Plugins :: Parent ......... SUCCESS [ 0.064 s]
[INFO] Plugin ServerService :: Plugin :: Parent ........... SUCCESS [ 1.382 s]
[INFO] Plugin ServerService :: Plugin :: Server ........... SUCCESS [ 3.827 s]
[INFO] Plugin ServerService :: Plugin :: IDE .............. FAILURE [ 4.870 s]
[INFO] Plugin ServerService :: Che Assembly :: Assembly Parent SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Workspace Agent Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Workspace Agent Tomcat Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: IDE Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Assemblies Tomcat SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.925 s
[INFO] Finished at: 2019-07-10T10:48:43+08:00
[INFO] Final Memory: 75M/1321M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.0.1:analyze-only (analyze) on project plugin-serverservice-ide: Dependency problems found -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.0.1:analyze-only (analyze) on project plugin-serverservice-ide: Dependency problems found
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Dependency problems found
at org.apache.maven.plugins.dependency.analyze.AbstractAnalyzeMojo.execute(AbstractAnalyzeMojo.java:261)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :plugin-serverservice-ide
I don't think I added a wrong dependency. Because when I
import org.eclipse.che.ide.ui.dialogs.DialogFactory;
in my java code, che says
The import org.eclipse.che.ide.ui.dialogs cannot be resolved.
But after I added the dependency, che can recognize it.
I don't know why this happens... The error message says Dependency problems found, but it didn't point out the real problem...
I've just checked and I didn't face any issues you mentioned above.
This my changes for the project:
diff --git a/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml b/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
index 1237c6e..a5eed89 100644
--- a/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
+++ b/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
## -28,6 +28,10 ##
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
+<dependency>
+ <groupId>org.eclipse.che.core</groupId>
+ <artifactId>che-core-ide-ui</artifactId>
+</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
diff --git a/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java b/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
index cb1cf58..0def9c2 100644
--- a/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
+++ b/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
## -8,13 +8,15 ##
*/
package org.eclipse.che.sample.ide;
-import javax.inject.Inject;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.rest.AsyncRequestFactory;
import org.eclipse.che.ide.rest.StringUnmarshaller;
+import org.eclipse.che.ide.ui.dialogs.DialogFactory;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
+import javax.inject.Inject;
+
/**
* Client for consuming the sample server service.
*
## -25,6 +27,7 ## public class MyServiceClient {
private AppContext appContext;
private AsyncRequestFactory asyncRequestFactory;
private LoaderFactory loaderFactory;
+ private DialogFactory dialogFactory;
/**
* Constructor.
## -38,8 +41,10 ## public class MyServiceClient {
public MyServiceClient(
final AppContext appContext,
final AsyncRequestFactory asyncRequestFactory,
- final LoaderFactory loaderFactory) {
+ final LoaderFactory loaderFactory,
+ final DialogFactory dialogFactory) {
+ this.dialogFactory = dialogFactory;
this.appContext = appContext;
this.asyncRequestFactory = asyncRequestFactory;
this.loaderFactory = loaderFactory;
## -52,6 +57,7 ## public class MyServiceClient {
* #return a Promise containing the server response
*/
public Promise<String> getHello(String name) {
+ this.dialogFactory.createChoiceDialog("1", "2", "", "", null, null);
return asyncRequestFactory
.createGetRequest(appContext.getWsAgentServerApiEndpoint() + "/hello/" + name)
.loader(loaderFactory.newLoader("Waiting for hello..."))

ComponentScan and import org.springframework.context.annotation.ComponentScan can not be resolved as a type

I have a problem with my project in Spring. Firstly I couldn't run it on the server but after downloading all resources again it started.
But now I have some imports which Spring can not see
For example:
import org.springframework.context.annotation.ComponentScan can not be resolved as a type.
and autwired value
#ComponentScan can not be resolved as a type.
Because of that hibernate is not creating tables in my database ( I think so )
Also two configuration classes have some errors:
The hierarchy of the type Spring4Initializer is inconsistent
SpringSecurityInitializer
public class Spring4Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { Spring4Configuration.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
#Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return new Filter[] { characterEncodingFilter };
}
}
SpringSecurityInitializer Multiple markers at this line
- The type org.springframework.web.WebApplicationInitializer cannot be resolved. It is indirectly referenced from
required .class files
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}
I've tried maven clean and maven build
[WARNING]
[WARNING] Some problems were encountered while building the effective model for pl.dmcs:eschool:war:1.0.0-BUILD-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-context:jar -> version ${org.springframework-version} vs 4.3.7.RELEASE # line 74, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.fasterxml.jackson.core:jackson-databind:jar -> version 2.8.8 vs 2.8.3 # line 157, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: javax.servlet:servlet-api:jar -> version ${servlet-api-version} vs 2.5 # line 254, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-context:jar -> version ${org.springframework-version} vs 3.0.5.RELEASE # line 271, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building E-School 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # eschool ---
[INFO] Deleting C:\Users\Piotr\Desktop\E-School\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Does anyone know what should I do with it to make hibernate working?
In Outline tree my function GetHibernateProperites() is marked as red
Have you included the spring-context in your maven dependencies? I think you are missing that dependency.

Maven is not launching the browser for selenium

I am doing a basic test in Selenium and I want it to execute from maven I am not getting any error but browser is not launched.and in TESTS section I get
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
my src/Test/java/Test.java is
public class Test {
public static void main(String[] args) throws Throwable {
System.setProperty("webdriver.gecko.driver","C:/Users/swkv8851/Downloads/geckodriver-v0.15.0-win32/geckodriver.exe");
Open open=new Open();
open.Opengmail();
}
}
and my src/main/java.Open.java is:
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Open {
WebDriver driver=new FirefoxDriver();
public void Opengmail() throws Exception{
driver.get("http://google.com");
driver.findElement(By.linkText("Gmail")).click();
Thread.sleep(5000);
driver.findElement(By.name("Email")).sendKeys ("somevalues");
String st=driver.findElement(By.xpath("//a[#class='need-help']")).getText();
System.out.println(st);
Assert.assertEquals("Find my account", st);
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
driver.findElement(By.name("Passwd")).sendKeys ("some string");
driver.findElement(By.id("signIn")).click();
}
}
MY POM file:
<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>SeleniumTestWithMaven</groupId>
<artifactId>SeleniumTestWithMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SeleniumTestWithMaven</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
OUTPUT of execution:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SeleniumTestWithMaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # SeleniumTestWithMaven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # SeleniumTestWithMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # SeleniumTestWithMaven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # SeleniumTestWithMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # SeleniumTestWithMaven ---
[INFO] Surefire report directory: C:\Personal\learn_selenium\workspace\SeleniumTestWithMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.294 s
[INFO] Finished at: 2017-04-04T16:23:45+05:30
[INFO] Final Memory: 9M/114M
[INFO] ------------------------------------------------------------------------
how can I my invoke my browser and perform test.
Selenium Version >3.0 requires GeckoDriver to run Firefox found # https://github.com/mozilla/geckodriver/releases
There is no test in your code (no #Test annotation)
You need something like this :
public class Test {
#Test
public void myTest() {
System.setProperty("webdriver.gecko.driver","C:/Users/swkv8851/Downloads/geckodriver-v0.15.0-win32/geckodriver.exe");
Open open=new Open();
open.Opengmail();
}
}

backtype.storm.generated.AlreadyAliveException

I am trying to submit a topology to my STORM cluster and I am getting the following error on running mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building storm-starter 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # storm-starter ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # storm-starter ---
[INFO] Compiling 15 source files to /Users/sharath/workspace/storm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/sharath/workspace/storm/src/jvm/storm/starter/CustomToplogy.java:[41,35] unreported exception backtype.storm.generated.AlreadyAliveException; must be caught or declared to be thrown
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.396 s
[INFO] Finished at: 2014-08-19T20:35:37+05:30
[INFO] Final Memory: 17M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project storm-starter: Compilation failure
[ERROR] /Users/sharath/workspace/storm/src/jvm/storm/starter/CustomToplogy.java:[41,35] unreported exception backtype.storm.generated.AlreadyAliveException; must be caught or declared to be thrown
[ERROR] -> [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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I did some research and found out that the error occurs if a topology with the same name already exists on the cluster. But I queried STORM and found that no such topology exists.
Can someone help me understand what is going on?
The code for the topology is below..
package storm.starter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.utils.Utils;
import storm.starter.spout.Spout;
import storm.starter.bolt.RedisBolt;
import java.util.*;
import backtype.storm.StormSubmitter;
public class CustomTopology {
public static void main(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
//List<String> hosts = new ArrayList<String>();
//String host = args[0];
String broker = "tcp://192.168.5.102:1443";
String client = "test_client";
String topic = "#";
String redis_host = "192.168.5.102:6379";
//hosts.add(host);
builder.setSpout(...); //Omitted for security
builder.setBolt(...); //Omitted for security
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
}
else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("CustomT1", conf, builder.createTopology());
Utils.sleep(10000);
cluster.killTopology("CustomT1");
cluster.shutdown();
}
}
}
I setup my storm infrastructure using https://github.com/miguno/wirbelsturm
Your topology isn't alive, maven is throwing that error during compilation.
unreported exception backtype.storm.generated.AlreadyAliveException;
must be caught or declared to be thrown
This means you must catch or specify an exception is thrown.
Change this line:
public static void main(String[] args) {
To this:
public static void main(String[] args) throws Exception {

Maven surefire tests failing in Spring framework project

Maven is unable to successfully run my JUnit tests though they are being run without any problem on my Eclipse. I'm unable to solve it from the debug messages.
It is probably something to do with the Spring config because my other JUnit tests not relying on Spring are working fine.
Adding the surefire plugin forkMode as Always didn't work either.
Maven output
mvn install ... ... [INFO] --- maven-surefire-plugin:2.10:test (default-test) # AppServer --- [INFO] Surefire report directory:
C:..\surefire-reports
Running com.ws.impl.BrowserServiceImplTest Tests run: 2, Failures: 2,
Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!
Failed tests: com.ws.impl.BrowserServiceImplTest.testGetStatuses()
com.ws.impl.BrowserServiceImplTest.testGetSellers()
Test class
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("classpath:test-context.xml")
public class BrowserServiceImplTest {
#Autowired
private BrowserServiceImpl browserServiceImpl;
#Test
public void testGetStatuses() {
// test code
}
// more code
}
Surefire report
<failure type="java.lang.NullPointerException">java.lang.NullPointerException
at com.ws.impl.BrowserServiceImplTest.testGetStatuses(BrowserServiceImplTest.java:48)
</failure>
Edit
Lines 48-49
List<String> statuses = browserServiceImpl.getStatuses();
assertEquals(12, statuses.size());
Edit 2
test-context.xml
<bean id="browserSvc" class="com.ws.impl.BrowserServiceImpl">
<property name="filterOptionsService" ref="filterOptionsService" />
</bean>
BrowserServiceImpl.java
#WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {
private FilterOptionsService filterOptionsService;
// more code
}

Resources