Java - Maven - OpenImaj project assembly error - java

I'm trying to assemble a project using maven and the OpenImaj library, I been following the instructions on this page http://www.openimaj.org/tutorial/getting-started-with-openimaj-using-maven.html but some of the process seems to be different from the one outline in the tutorial, I have tried this on two different computers (mac and pc) and received the following errors/steps, any idea of where/what I am doing wrong will be helpful.
after running the mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate line I am prompt to "Choose a number or apply filter" where the default is 284.
Once I select 284 (should I be selecting anything else?), I'm being prompt to select "maven-archetype-quickstart version" where I choose the latest 6:1.1, following by the groupId, artifactId, version, package, and Y confirmation, this result with 'Build Success' and create the directory as well as the pom.xml file on my computer.
When I navigate to the project folder "cd projectName" and run the mvn assembly:assembly command, I first see that a few of the packages are being collected, then I see a "Build Failure" notification -"Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5.... No assembly descriptors found.
any idea what I am doing wrong and how I can get the OpenImaj lib integrated into a project, should I be downloading the SVN version and attempt to set the projects from local libraries.
Many thanks in advance!

Just add this plugin to your pom.xml. This solved the problem for me:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

Are you sure you're entering the maven command in step 1 correctly? You should only see three options (just confirmed this is working on both OSX, debian & ubuntu):
abe:~ jon$ mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: http://maven.openimaj.org/archetype-catalog.xml -> org.apache.maven.archetypes:maven- archetype-quickstart (An archetype which contains a sample Maven project.)
2: http://maven.openimaj.org/archetype-catalog.xml -> org.openimaj:openimaj-quickstart-archetype (Maven quickstart archetype for OpenIMAJ)
3: http://maven.openimaj.org/archetype-catalog.xml -> org.openimaj:openimaj-subproject-archetype (Maven archetype for creating OpenIMAJ subprojects with the most of the standard configuration completed automatically)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
You then need to pick the org.openimaj:openimaj-quickstart-archetype option from the list (probably #2).

I had faced similar issues and finally worked it out. There are two things to note here. One is the network we are using and second is the maven tool we are using.
In your eclipse IDE go to window -> preferences.
Under maven tab go to installations sub-tab. Instead of using the embedded maven add filepath to maven installed on your system (The one command Line uses).
Under General Tab go to Network connections tab. Change the active provider.
Neither of the above will completly build the project successfully in one go. But each combination of network and maven will download some jars. Once you try two to three combinations you will have all the jars and the project will build successfully.

Related

Facing Issue with Maven custom archtype

I'm trying to generate custom maven archtype, I'm trying below example to generate custom maven spring boot archtype:
Custom Maven Archtype
If I try to run the below maven generate command - works good
mvn archetype:generate \
-DarchetypeGroupId=com.romeh.spring-boot-archetypes \
-DarchetypeArtifactId=spring-boot-quickstart \
-DarchetypeVersion=1.0.0 \
-DgroupId=com.test \
-DartifactId=sampleapp \
-Dversion=1.0.0-SNAPSHOT \
-DinteractiveMode=false
But if I change the Group ID with my custom name - it started failing
For example if I change this from -DarchetypeGroupId=com.romeh.spring-boot-archetypes to -DarchetypeGroupId=com.test.spring-boot-archetypes
I'm getting below error message - if I change the group id.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:26 min
[INFO] Finished at: 2018-04-19T11:45:36-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project spring-boot-quickstart: The desired archetype does not exist (com.test.spring-boot-archetypes:spring-boot-quickstart:1.0.0) -> [Help 1]
Please note that - before executing this command I've changed group id in pom.xml and archetype-catalog.xml as well.
Can you please help me to fix this issue - not sure what i'm doing wrong here.
You just should not do that. These properties
-DarchetypeGroupId=com.romeh.spring-boot-archetypes
-DarchetypeArtifactId=spring-boot-quickstart
-DarchetypeVersion=1.0.0
identifies the archetype; it's like when you have some JAR and you want to add it to your project you need to provide groupId, artifactId and version.
The same approach is used for archetypes! Archetypes are packaged up in a JAR and they consist of the archetype metadata which describes the contents of the archetype.
Those properties say Maven what archetype (like what JAR) it should run to generate your app skeleton. And if you change them - Maven won't just find the appropriate JAR in the repository.
Instead, you should modify:
-DgroupId=com.test
-DartifactId=sampleapp
-Dversion=1.0.0-SNAPSHOT
Those will be properties of your project generated by that archetype.

Maven Jenkins job skips all modules if one fails to build

In Jenkins, I have a Maven project with the following structure:
x proftaakmaven
- AutosimulatieSysteem
- LandenMonitoringSysteem
- PolitieSysteem
x Verplaatsingssysteem
- VerplaatsingREST
- VerplaatsingSOAP
- VerplaatsingCommon
- VerplaatsingenRabbitMQ
- RabbitMQ-Proof-of-Concept
- VerplaatsingenRabbitMQTestClient
The Maven reactor constructs this building order:
[INFO] Reactor Build Order:
[INFO]
[INFO] AutoSimulatie
[INFO] LandenMonitorSysteem
[INFO] PolitieSysteem
[INFO] VerplaatsingenSysteem
[INFO] VerplaatsingenCommon
[INFO] VerplaatsingenREST
[INFO] VerplaatsingenSOAP
[INFO] RabbitMQ-Proof-of-Concept
[INFO] VerplaatsingenRabbitMQ
[INFO] VerplaatsingenRabbitMQTestClient
[INFO] proftaakmaven
However, due to a current failure in 'LandenMonitorSysteem' source code, Maven fails on building the other modules as well. This makes the Jenkins job fail.
I have tried running Maven with --fail-never and --fail-at-end. But neither seem to have any effect.
How would I be able to continue building all the modules, even if one fails?
Thanks.
--fail-at-end should be the thing to use.
If that doesn't work you could use -pl to specify the list of working projects.
If you use the -am flag as well you can specify the target you are interested in building and Maven will calculate the dependency tree for you.
I.E. mvn clean install -pl VerplaatsingenRabbitMQTestClient -am
I have found the solution. The problem was the way that I provided the argument. In Jenkins 2.0, the job should be configured like this :
The settings inside the job

Ways to make maven build faster?

I have a multi module java project. Maven takes almost around 40 secs to build it. I have tried maven with multi threaded builds too by specifying -T and -C args for no of threads and cores to be used. But I haven't seen any significant improvement in wall time of my builds.
I am using maven 3.2.3 and sometimes I need to build my project very frequently.
I know that clean goal take a lot of time but I can not omit it.
Suggestions please....
EDIT:
Note: In my case clean is not taking much time. It finishes in 1 sec. install is taking rest of the time.
Note: First thing is AFAIK, No other in built options available in maven apart from the all answers here.
Running maven build with Multiple threads works for me to speed up the builds.
For example :
mvn clean install -T100
where -T is for specifying how many threads you want based on your
hardware.
Below are the variants from wiki
Maven 3.x has the capability to perform parallel builds. The command
is as follows:
mvn -T 4 clean install Builds with 4 threads
mvn -T 1C clean install 1 thread per cpu core
mvn -T 1.5C clean install 1.5 thread per cpu core
How Execution is evaluated(See Parallel builds in Maven 3)?
Each node in the graph represents a module in a multi-module build, the "levels" simply indicate the distance to the first module in the internal reactor dependency graph. Maven calculates this graph based on declared inter-module dependencies for a multi-module build. Note that the parent maven project is also a dependency, which explains why there is a single node on top of most project graphs. Dependencies outside the reactor do not influence this graph.
Finally if you want to skip test execution you can also use -DskipTests as well.
Caution : Some of your plugins may not be compatible for multithreaded builder, it may work. but it will give below warning message. you may need to see plugin documentation for multithreading support.
[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project *
[WARNING] * contains the following plugin(s) that have goals not marked *
[WARNING] * as #threadSafe to support parallel building. *
[WARNING] * While this /may/ work fine, please look for plugin updates *
[WARNING] * and/or request plugins be made thread-safe. *
[WARNING] * If reporting an issue, report it against the plugin in *
[WARNING] * question, not against maven-core *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked #threadSafe in test-project:
[WARNING] de.dentrassi.maven:rpm:0.9.2
[WARNING] Enable debug to see more precisely which goals are not marked #threadSafe.
[WARNING] *****************************************************************
On my actual project :
mvn clean install [INFO] Total time: 01:05 h
mvn clean install -DskipTests [INFO] Total time: 18:35 min
mvn clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 10:58 min
mvn -T 1C clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 04:00 min
We can also skip the javadoc to be generated as Archmed commented by adding -Dmaven.javadoc.skip=true mvn -T 1C clean install -Dmaven.test.skip -DskipTests -Dmaven.javadoc.skip=true
Don't use * imports, on IntelliJ, choose > Analyze > Run inspection by name > * imports , to find all * imports and correct it.
Remove all unused imports in your project > on Intellij > Analyze > Run inspection by name > unused imports
Remove all unused code (classes, variable, field, parameter, etc..), on Intellij : Analyze > run inspection by name > unused declaration.
Upgrade to last JAVA VERSION
I have found that the task mvn clean, is taking 2 minutes to clean the TARGET folder before building. I did create a new task called quickclean, and I am using it instead of clean, this way mvn -T 1C quickclean install -Dmaven.test.skip -DskipTests . This new task quickclean is only renaming the build folder from TARGET to TARGET-yyyy-MM-dd-HH-mm(what is VERY FAST). So now, every time you make a new mvn quickclean install..., you have a folder with the time of the build. The inconvenient, it's that this may take a lot of space on the hard disk, so you have to clean all these directories sometimes. So for that I have created another task called: trashclean, to put all this folder to trash. I am running this tasks maybe on time per week. or month, depending on my work mvn trashclean.
Here is what you need to add to your pom.xml if you want to use this concept
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd-HH-mm</maven.build.timestamp.format>
<trashdir>trash/target-${maven.build.timestamp}</trashdir>
</properties>
<profile>
<id>quickclean</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>rename_target</id>
<phase>pre-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<move todir="${trashdir}" failonerror="false">
<fileset dir="target/"/>
</move>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>trashclean</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>clean_trash</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete dir="trash/" failonerror="false"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
You can optimize the build by using of some small-2 trick like
If you have written Junit Test and dont want to run test case every time you can use -DskipTests=true
Locally Install Nexus or Repositories
You can adjust memory configurations to optimum for eg: add this line to mvn.bat set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m
For more information you can check How to Speed Your Maven build
You can do a hacky way if you have some extra RAM as I do, and you don't need SSD, because it's sensitive for SSD to do a lot of read-writes. Even if you disable +a bit (MacOS - I don't remember if Win have similar issue). But
create RAM drive (number of ways depends on your OS) and mount it to /Users/Username/volatile folder
locate maven-module-builder-X.X.X.jar in MVN_HOME/lib
in JAR modify file org/apache/maven/model/pom-4.0.0.xml by modifying
<build><directory>/Users/Username/volatile/${project.groupId}/${project.artifactId}/${project.version}/target
From now on all project compilations will be done in memory. And it's a difference even in comparison with SSD.
Yes, its hack and some maven plugins can stop working BTW.
If using commandline you can check how many cores your machine has and use all of them, if you also want to skip your tests, you can add -DskipTests
For example, I have 8 core processor:
mvn -T 8C clean install -DskipTests
Apart from parallel run which many of the folks have already mentioned, try these maven options which would speed up build
-XX:+TieredCompilation -XX:TieredStopAtLevel=1
You can try turbo-maven-plugin to help speed up your multi module Maven builds locally (I am one of the plugin authors)?
https://github.com/sparebank1utvikling/turbo-maven-plugin
It works by analyzing what modules actually have code changes, and build only those and the modules dependent on them. More info about how it works here:
https://medium.com/sparebank1-digital/speed-up-your-multi-module-maven-builds-with-turbo-maven-plugin-4be0eb2a2601
Low-Level speed using Ramdisk (Windows)
My additional trick is using a ramdisk
Create a Ramdisk of 2GB (in example D:)
Install IDE, Maven, JDK and the .m2/repository to that Ramdisk (D:/m2/).
Edit the Maven's D:/maven/conf/settings.xml to use that Ramdisked repo (<localRepository>D:/m2</localRepository>)
Put the project into the ramdisk.
Run the project having its temp-folder in the Ramdisk.
On my machine I turned
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.954 s (Wall Clock)
[INFO] Finished at: 2021-02-17T13:07:51+01:00
[INFO] Final Memory: 55M/642M
[INFO] ------------------------------------------------------------------------
Into
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.805 s (Wall Clock)
[INFO] Finished at: 2021-11-11T10:48:14Z
[INFO] ------------------------------------------------------------------------
Both results are high-end (-DskipTests -T 12)
Warning: Do not forget to persist the ramdisk before shutdown or your work is lost.
Look at this beast:
If you are using spring boot with maven and you feel like dependencies are coming slow to your system, try following setting in pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath />
</parent>
I experienced that version 2.7.0 downloads the dependencies faster than other versions.

Maven: Build only one module out of multi-module project

I have a multi-module Maven project wherein I just want to release an update module rather than the entire project. This is due to some specific requirements, wherein a release of entire project is uncalled for - only a subset of the library needs the fixes and thus the release.
However, when I run a mvn release:prepare I get the following error Non-resolvable parent POM - I have setup the parent POM relationship in the module project with relativePath tag but that does not seem to work.
Is it possible to release only a module rather than releasing the entire project.
Thanks in advance.
EDIT
Parent pom
<groupId>com.domain</groupId>
<artifactId>project-parent</artifactId>
<version>0.5.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>library1</module>
<module>library2</module>
<module>library3</module>
</modules>
The module POMs are as under:
<parent>
<groupId>com.domain></groupId>
<artifactId>project-parent</artifactId>
<version>0.5.1-SNAPSHOT</version>
</parent>
<artifactId>library1</artifactId>
Now I just want to release the new version of library1 and not others
mvn -pl .,library1 clean install
The "." will build your parent pom.xml and "library1" is the module name you gave it.
If you don't want to build the parent pom.xml, you can also do:
mvn -pl library1 clean install
or in your case, maybe:
mvn -pl library1 deploy
I used "deploy" because "release" is not a Maven build lifecycle phase.
Try running the maven commands from the parent project/directory with the -pl <project name> switch.
the trick is both:
to repeat the -pl Param inside an additional -Darguments Param, to pass the -pl Param to the Child-Maven-Processes
the mysterious mavenExecutor, to be able to create the Child-Maven-Processes using the given -pl Param
This should work:
mvn -pl library1 -DmavenExecutorId=forked-path -Darguments="-pl library1"
I think maven is trying to tell you that the parent you defined is not released/stable. In your pom the parent version is "0.5.1-SNAPSHOT" which can not/should not work if you want to release a single library module as it would be pointing to something that is not uniquely defined. Is there a stable version you can point to instead? Otherwise maybe the -am switch works in combination with -pl?
Edit
I tried this just now with maven 3.2 and it does ask me for what version the parent should be set/resolved to. It is as I stated previously you need stable version numbers for the release to work
mvn release:prepare -pl library1
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building library1 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) # library1 ---
[INFO] Verifying that there are no local modifications...
[INFO] ignoring changes on: **\release.properties, **\pom.xml.next, **\pom.xml.releaseBackup, **\pom.xml.backup, **\pom.xml.branch, **\pom.xml.tag [INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\temp\mavenTest\library1
[INFO] Checking dependencies and plugins for snapshots ...
There are still some remaining snapshot dependencies.
: Do you want to resolve them now? (yes/no) no: : yes
Dependency type to resolve,: specify the selection number ( 0:All 1:Project Dependencies 2:Plugins 3:Reports 4:Extensions ): (0/1/2/3) 1: : 1
Dependency 'testme:parent' is a snapshot (1.1-SNAPSHOT)
: Which release version should it be set to? 1.1: :

Maven error: "You don't have a SNAPSHOT project in the reactor projects list."

What on earth does this mean? Cant find any help via google.
> mvn release:prepare
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Base 1.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) # base ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.386s
[INFO] Finished at: Tue Oct 08 08:22:46 EST 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project base: You don't have a SNAPSHOT project in the reactor projects list. -> [Help 1]
release:prepare command is supposed to prepare your snapshot project for the release. It sounds like you don't have such a snapshot project.
Here's the full details what it'll do: http://maven.apache.org/maven-release/maven-release-plugin/examples/prepare-release.html
If you're sure you should be releasing, you should be working on a maven module that has version ending with -SNAPSHOT.
Update: like noted by #khmarbaise in the comments, if your release has failed, you should do release:rollback to go back to previous state. Note though that it is not supported if you release through jenkins (jenkins issue), and it won't rollback the tags.
Don't needed manually edit pom.xml.
You can use "mvn versions:set" for batch update, something like this:
mvn versions:set -DnewVersion=1.0.3-SNAPSHOT
I've had the same error with Jenkins. In a previous release, Jenkins updated the version of the POM to a non-snapshot version, but the build failed before Jenkins could set the version to a -SNAPSHOT version again. Afterwards, making a release resulted in the error described above.
Fixing this is easy: just manually change the version of your app in pom.xml to a -SNAPSHOT version.
I know this is an old question but I had this issue recently and I found 2 solutions that others may find useful. I am using bamboo as my CI tool. The issue was that there was an error in the bamboo build leaving bamboo in an incorrect state. It had locally updated my project pom.xml with the new release version but had not checked this into SVN. The two solution that worked for me were:
Either
Delete the bamboo build-dir directory for the project and run the release again: rm -rf /opt/bamboo-home/xml-data/build-dir/PROJECT_NAME-RELEASE-JOB1
OR
Run the maven release from the command line using the following commands:
mvn release:prepare -DignoreSnapshots -Dresume=false
mvn release:perform
No need to update versions manually as that is time consuming, if version change is all you need, there is a different command that only updates the pom versions, just like updating them manually:
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=1.0.XX-SNAPSHOT

Categories