Why can't I create a Maven project? - java

mvn -version
mvn archetype:create \
> -DgroupId=com.tobilko \
> -DartifactId=site \
> -DarchetypeArtifactId=maven-archetype-webapp
I'm going to create a project with Maven using a maven-archetype-webapp archetype. Why can't I do it? I've just started learning Maven so the error doesn't tells me anything:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-
plugin:2.3:create (default-cli) on project standalone-pom: Unable to
parse configuration of mojo org.apache.maven.plugins:maven-archetype
plugin:2.3:create for parameter #: Abstract class or interface
'org.apache.maven.artifact.repository.ArtifactRepository' cannot be
instantiated: org.apache.maven.artifact.repository.ArtifactRepository.
<init>() -> [Help 1]
I don't want to have any other archetypes or a default archetype.

Dont use create use generate . Something like this
mvn archetype:generate
-DgroupId=com.tobilko
-DartifactId=site
-DarchetypeArtifactId=maven-archetype-webapp

archetype:create is deprecated
instead use
archetype:generate
See this link for the reference since you have started learning maven

Related

How to run specific test class in subfolder with maven command?

I have a question in regards to running a single test class through maven. More specifically, I have a project structure which looks like this:
And I would like to run the integration test inside the StatusSocketIT class through a maven command. I tried therefore the following maven command:
mvn test -Dtest=todolist.websocket.src.it.java.org.smart.todolist.websocket.StatusSocketIT
but it fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project backend: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
which tells that the tests cant be executed. I have also tried other path names like for instance org.smart.todolist.websocket.StatusSocketIT but this also throws the same error. Would anyone maybe know what the issue is? Thanks in advance
Change the command to:
mvn test -Dtest=org.smart.todolist.websocket.StatusSocketIT
Only the "path" inside src/it/java is part of the class name (its package).
In addition, make sure you have the src/it/java directory configured as a test directory in your pom file:
<build>
<testSourceDirectory>src/it/java</testSourceDirectory>
</build>

vaadin widgetset do not work. bug in maven plugin vaadin

I've create a vaadin application with maven using the following comand:
mvn archetype:generate -DarchetypeGroupId=com.vaadin
-DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=7.7.12-DgroupId=com.example -DartifactId=myapplication -Dversion=0.1 -Dpackaging=war
It has created a right project; Now I'm going to create a custom widget, follow the instruction on
https://vaadin.com/docs/v7/framework/gwt/gwt-eclipse
The wizard new-->other--> Vaadin 8 widget creates the necessary file:
But when I try to compile I get:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project myapplication: Compilation failure:
Compilation failure: [ERROR]
/C:/Users/fmi/eclipse-workspace/myapplication/src/main/java/com/example/client/mycomponent/MyComponentWidget.java:[3,37]
package com.google.gwt.user.client.ui does not exist [ERROR]
/C:/Users/fmi/eclipse-workspace/myapplication/src/main/java/com/example/client/mycomponent/MyComponentWidget.java:[6,40]
cannot find symbol [ERROR] symbol: class Label
I know that may be I have to add dependency in the pom, but I'm asking why the wizard has this bug?
Note in the picture I see Vaadin 8 widget, while the project has been created with archetype 7.7
Is a bug in the wizard or a mistake by me?
thanks
I've resolved adding:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
</dependency>
It is necessary to compile widgets; It is still unclear why in the documentation has not reported.

Sonar error : Wrong source path use by the analyser

I run the command below with GitLab CI / CD:
mvn -s /etc/gitlab-runner/maven/settings-maven.xml --batch-mode test sonar:sonar
-Dsonar.java.source=1.8
-Dsonar.host.url=${SONARHOST}
-Dsonar.projectKey=${SONARKEY}
-Dsonar.projectName=${SONARNAME}
-Dsonar.projectVersion=${SONARVERSION}
-Dsonar.sources=myproject_core/src/main/java,myproject_service/src/main/java,myproject_persistance/src/main/java
-Dsonar.language=java
-Dsonar.java.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.java.libraries=**/*.jar
-Dsonar.java.coveragePlugin=jacoco
-Dsonar.surefire.reportPaths=myproject_core/target/surefire-reports,myproject_service/target/surefire-reports,myproject_persistance/target/surefire-reports
-Dsonar.junit.reportPaths=myproject_core/target/surefire-reports,myproject_persistance/target/surefire-reports,myproject_service/target/surefire-reports
-Dsonar.verbose=true
-Dsonar.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.jacoco.reportPaths=myproject_core/target/jacoco.exec,myproject_service/target/jacoco.exec,myproject_persistance/target/jacoco.exec
-Dsonar.exclusions=**/*Test*/**
-Dsonar.tests=myproject_core/src/test,myproject_service/src/test,myproject_persistance/src/test
So, I want to analyse 3 project core, service and persistance (I have 7 modules in my project)
myproject-parent
myproject-core
myproject-persistance
myproject-service
myproject- ...
But, I have this error :
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/**myproject_persistance/myproject_core**/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/myproject_persistance/myproject_core/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources
On this sonarqube error, i can see that in the path, module persistance is include on module core, but this is not the case
I'm looking for why but I can't find. Have you ever had this problem ?

How do I use "projectVersionPolicyId" in Maven Release Plugin?

There is a parameter projectVersionPolicyId in many mojos of Maven Release Plugin, e.g. http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#projectVersionPolicyId. However, it seems that they provided no examples of how I can use it.
When I try:
$ mvn --batch-mode release:prepare -DprojectVersionPolicyId=foo
It shows an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M1:prepare (default-cli) on project maven-release-test: Policy 'foo' is unknown, available: [default] -> [Help 1]
It looks like that there only 1 available policy (which is default). Is there any way to add more possible policies?
You can use SemVerVersionPolicy as well

Maven doesn't recognize parameter when containing "-"

I was trying to test this maven plugin on a simple spring-boot project. But I'm facing an issue with mojo parameters, when I use parameter containing a "-" along with goals it doesn't seem to work:
$ mvn clean install fabric8:build fabric8:resource \
> -Dfabric8.openshift.enableAutomaticTrigger=false \
> -Dfabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll=true
But when I put these parameters as system properties in project's pom.xml. They seem to be picked by maven plugin and work as they are supposed to do. I added this to pom like this:
<properties>
<fabric8.openshift.enableAutomaticTrigger>false</fabric8.openshift.enableAutomaticTrigger>
<fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>true</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
</properties>
I'm a big confused here. Can anyone please tell me why it's not working in former case? Is there some kind of naming convention for mojo parameters that we're supposed to follow?
I suggest you to use a workaround (seems to me a faster solution than debug maven) :
<properties>
<f8.autoTrigger>your_default_here</f8.autoTrigger>
<f8.enrichAll>your_other_default_here<f8.enrichAll>
<fabric8.openshift.enableAutomaticTrigger>${f8.autoTrigger}</fabric8.openshift.enableAutomaticTrigger>
<fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>${f8.enrichAll}</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
</properties>
And if you want to override your defaults you can invoke maven like :
$ mvn clean install fabric8:build fabric8:resource \
> -Df8.autoTrigger=false \
> -Df8.enrichAll=true
It is even shorter :)

Categories

Resources