Why does using limit modules am getting namespace error? - java

I am getting below error while using mvn clean package. Even after limiting modules in pom.xml
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:2.7.0:compile (default-compile) on project com.binding.rest.runtime.schema: Compilation failure: Compilation failure: [ERROR] C:\Users\runtime\plugins\com.binding.rest.runtime.schema\src\com\runtime\schema\Wsdl4JsonUtils.java:[5] [ERROR] import javax.xml.namespace.QName;
I tried to limit modules in below manner:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<compilerArgs>
<arg>-warn:none</arg>
<arg>-err:none</arg>
<arg>-warn:+discouraged,forbidden</arg>
<arg>--limit-modules</arg>
<arg>java.base,java.compiler,....</arg>
</compilerArgs>
</configuration>
</plugin>

Related

kapt not working with maven and dagger in mixed kotlin/java project

Kapt doesnt work with maven, if we dont use kapt and just use the maven compiler for java it generates dagger code perfectly fine, but the problem is that java compiles after kotlin compiles and kotlin gives and error because it can't use dagger components before they are created, so the solution would be to use kapt.
this is the plugin configuration
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- Specify your annotation processors here. -->
<annotationProcessorPath>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.9</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.myanimelist/com.example.myanimelist.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and this is the error that gives
"C:\Program Files\BellSoft\LibericaJDK-17-Full\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList -Dmaven.home=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4 -Dclassworlds.conf=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=63596:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2022.1 compile
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.example:MyAnimeList >-----------------------
[INFO] Building MyAnimeList 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- kotlin-maven-plugin:1.6.21:kapt (kapt) # MyAnimeList ---
[WARNING] 'tools.jar' was not found, kapt may work unreliably
[WARNING] C:\Users\Roberto\.m2\repository\org\checkerframework\checker-compat-qual\2.5.5\checker-compat-qual-2.5.5.jar: (-1, -1) The root is ignored because a module with the same name 'org.checkerframework.checker.qual' has been found earlier on the module path at: C:/Users/Roberto/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-base\17.0.1\javafx-base-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.base' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-controls\17.0.1\javafx-controls-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.controls' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-fxml\17.0.1\javafx-fxml-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.fxml' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-graphics\17.0.1\javafx-graphics-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.graphics' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
#Component(modules = {FiltersModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
#Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
#Component(modules = {RepositoriesModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
#Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
#Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
#Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
#Module(includes = RepositoriesModule.class)
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
#Module
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt: (4, 46) Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt: (3, 46) Unresolved reference: DaggerControllersComponent
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.254 s
[INFO] Finished at: 2022-05-16T00:29:31+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.6.21:kapt (kapt) on project MyAnimeList: Compilation failure: Compilation failure:
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
[ERROR] #Component(modules = {FiltersModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
[ERROR] #Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
[ERROR] #Component(modules = {RepositoriesModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
[ERROR] #Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
[ERROR] #Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
[ERROR] #Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
[ERROR] #Module(includes = RepositoriesModule.class)
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
[ERROR] #Module
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt:[4,46] Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt:[3,46] Unresolved reference: DaggerControllersComponent
[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
Process finished with exit code 1
I have tried using older jdks versions but nothing changed

How to run test from different folder?

I have project
my-tests
src
test
java
my
demo
srv
src
main
java
my
demo
I want to run mvn clean install on srv and then to run the tests from my-tests
I tried to add plugin to the pom.xml of srv
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-test-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>../my-tests</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I got an error of compile
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.592 s
[INFO] Finished at: 2020-04-27T16:35:14+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project sapinttest-srv: Compilation failure: Compilation failure:
[ERROR] /C:/Users/Downloads/app/integration-tests/src/test/java/my/company/HelloWorldServletTest.java:[3,22] package io.restassured does not exist
[ERROR] /C:/Users/Downloads/app/integration-tests/src/test/java/my/company/HelloWorldServletTest.java:[4,47] package org.jboss.arquillian.container.test.api does not exist
[ERROR] /C:/Users/Downloads/app/integration-tests/src/test/java/my/demo/HelloWorldServletTest.java:[5,34] package org.jboss.arquillian.junit does not exist
[ERROR] /C:/Users/Downloads/app/integration-tests/src/test/java/my/demo/HelloWorldServletTest.java:[6,37] package org.jboss.arquillian.test.api does not exist
[ERROR] /C:/Users/Downloads/app/integration-tests/src/test/java/my/demo/HelloWorldServletTest.java:[7,37] package org.jboss.shrinkwrap.api.spec does not exist
[ERROR] /C:/Users//Downloads/app/integration-tests/src/test/java/my/demo/HelloWorldServletTest.java:[8,17] package org.junit does not exist
when I tried to run test from the my-tests folder the compile was ok but the tests didn't run
mvn clean install -DskipTests=false
Could you advise me please ?
Fixing compilation errors
The error message states that some third library packages could not be found.
Being my-tests a Maven module, you should add to its pom.xml the dependencies that contains these packages.
pom.xml
<project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- TODO: Add other dependencies here. -->
</dependencies>
...
</project>
To find which dependency contains the package, you could search on Maven Central using the following criteria:
fc:package-name
e.g.:
fc:org.jboss.arquillian.junit
Direct link: https://search.maven.org/search?q=fc:org.jboss.arquillian.junit
Changing the test folder
Being your goal simply running tests on a folder different than src/test/java, you should change the testSourceDirectory property.
pom.xml
<project>
<build>
<testSourceDirectory>${project.basedir}/src/custom-test-folder/java</testSourceDirectory>
</build>
...
</project>

Custom doclet in a maven project - invalid flag

I am trying to generate javadoc on my maven project. I am using Java 1.8, and have written a small doclet project. The pom on my project has -
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<aggregate>true</aggregate>
<doclet>org.mydoclet.MyDoclet</doclet>
<docletArtifact>
<groupId>mydoclet</groupId>
<artifactId>mydoclet</artifactId>
<version>0.0.1-SNAPSHOT</version>
</docletArtifact>
<additionalOptions>
<additionalOption>-views</additionalOption>
</additionalOptions>
<useStandardDocletOptions>false</useStandardDocletOptions>
<destDir>docs</destDir>
</configuration>
</plugin>
</plugins>
</build>
I try to run javadoc:aggregate on this. I get an error
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:aggregate (default-cli) on project <>: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - javadoc: error - invalid flag: -Xdoclint:none
[ERROR]
[ERROR] Command line was: <javahome/bin>/javadoc #options #packages
Any ideas on what I am doing wrong?
I have been following the Maven page on writing doclets - https://maven.apache.org/plugins/maven-javadoc-plugin/examples/alternate-doclet.html#

Scala/Java Project not finding Dependencies during Maven compile

I have a Java/Scala hybrid project. When building in Intellij, things work fine. However, trying to run Maven builds from command line is giving me this error when running 'mvn clean install':
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:12: error: object model is not a member of package com.test.userlib
[ERROR] import com.test.userlib.model.cte.{ItemResponse, CteUser}
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:13: error: object utils is not a member of package com.test.userlib
[ERROR] import com.test.userlib.utils.UserLibProperties
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:26: error: not found: value UserLibProperties
[ERROR] .hosts(UserLibProperties.CTE_USERSERVICE_HOST + ":" + UserLibProperties.CTE_USERSERVICE_PORT)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:32: error: not found: value UserLibProperties
[ERROR] ClientAuthTlsConfigUtil.createSslContext(new File(UserLibProperties.CTE_USERSERVICE_KEYSTORE),UserLibProperties.CTE_USERSERVICE_KEYSTORE_PASSWORD,new File(UserLibProperties.CTE_USERSERVICE_TRUSTSTORE),UserLibProperties.CTE_USERSERVICE_TRUSTSTORE_PASSWORD)
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:35: error: not found: type CteUser
[ERROR] protected def getUser(dn :String) :CteUser = {
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:36: error: not found: value UserLibProperties
[ERROR] val rb = RequestBuilder().url(s"${UserLibProperties.CTE_USERSERVICE_ENDPOINT}/user?dn=${URLEncoder.encode(dn,"utf-8")}&aacAttribs=true").buildGet
[ERROR] ^
[ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:42: error: not found: type ItemResponse
[ERROR] case HttpResponseStatus.OK => new ObjectMapper().readValue(respTry.get.getContent.toString("UTF-8"), classOf[ItemResponse]).getItem.getUser
[ERROR] ^
[ERROR] 7 errors found
So, clearly my Scala class isn't finding the Java dependencies it needs. Here's my project's structure:
And here is the build portion of my pom.xml:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Do I have to add the classpath to the Scala compiler somehow?
I think UserLibProperties file should be in proper file extension UserLibProperties.scala. Please check you folder and do a list command and check for file extensions, in Intelij it will work without proper extension.
I think, SBT is best way to build a hybrid project.
For example:
https://github.com/databricks/learning-spark/blob/master/build.sbt
It has little learning curve, but worth to invest time in SBT.

maven debugging in Vagrant - HADOOP YARN application

I have installed Vagrant as a VM (single node) from this repository and then I installed maven inside so that I can create easily my HADOOP YARN jar files. When I am trying to build my jar mvn package I am getting an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project YarnTestClient: Compilation failure: Compilation failure:
[ERROR] /vagrant/openlab_ship_proto/YARN/src/main/java/ru/yandex/cern/yarntest/NMCallbackHandler.java:[16,25] generics are not supported in -source 1.3
[ERROR] (use -source 5 or higher to enable generics)
I have searched the whole internet but nothing solved my problem. Had anyone faced the same problem before? Thanks for your help.
Add this snippet to your pom.xml, if build tag didn't exist in pom.xml, maven would build java with source 1.3
<build>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>

Categories