How to build multiple projects (maven and scala) using batch file - java

I am trying to build maven project as well as scala project together one by one using a windows batch file. For this I have created a batch file in the root folder and written following lines inside it. Although my maven projects are building successfully but the scala project are failing to build.
call mvn -f A/pom.xml clean install -U
call sbt B\build.sbt clean compile -U
call mvn -f C/pom.xml clean install -U
call sbt D\build.sbt clean compile -U
The error I am getting is:
[warn] Executing in batch mode.
[warn] For better performance, hit [ENTER] to switch to interactive mode,
or
[warn] consider launching sbt without any commands, or explicitly passing
'shell'
[info] Set current project to my project(in build file:/C:/sample-
project/MyProject/)
[error] Expected ID character
[error] Not a valid command: B
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: B
[error] B\build.sbt
[error] ^

[SOLUTION]
The following worked for me...
cd A
call mvn clean install -U
echo Completed building A
cd ..
cd B
call mvn clean install -U
echo Completed building B
cd ..
cd C
call sbt clean compile -U
echo Completed building C
cd ../
cd D
call mvn clean install -U
echo Completed building D
cd ..
cd E
sbt clean compile
echo Completed building E

Related

error:Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.11:dockerBuild dockerizing JHipster-Registry

When I run this command:
mvn -e package -Pprod verify jib:dockerBuild
in jhipster-registry standard project, to dockerize this application, I get this error:
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.11:dockerBuild (default-cli) on project jhipster-registry: Invalid image reference: JHipster Registry:5.0.0 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.11:dockerBuild (default-cli) on project jhipster-registry: Invalid image reference: JHipster Registry:5.0.0
The link suggested in Help1 is:
https://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
This is a "generic error message".
My solution is:
docker system prune
This clean the docker images/container and the build docker images of registry gonna be ok.
delete target file from you project, and then execute inside terminal this command ./mvnw or ./mvnw install
and after that try again with this command mvn -e package -Pprod verify jib:dockerBuild inside terminal also

How to run maven command in AWS Device Farm

I am trying to run my java mobile project in device farm using maven.
When I run this command on my local machine in the right directory it works:
mvn test -D "cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps --tags #InstallApp"
I put this command on the yaml file in the aws device farm but it doesn't work.
This is the error I get:
[DeviceFarm] echo "Start Appium TestNG test"
Start Appium TestNG test
[DeviceFarm] mvn test -D
"cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps
--tags #InstallApp"
[INFO] Scanning for projects...
[INFO] BUILD FAILURE
[ERROR] The goal you specified requires a project to execute but there
is
no POM in this directory (/tmp/scratchncneoU.scratch/test-
packageO6o8s7).
Please verify you invoked Maven from the correct directory. -> [Help 1]
How can I run this maven command in device farm? Where is the pom located there?
Thanks
After typing this command in the yaml file:
[DeviceFarm] java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="classpath:features" --glue cucumber.steps --tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
I get an error of: Couldn't find the testng.xml in the jar file although I have this in my pom:
<directory>${project.basedir}/src/test/java/cucumber</directory>
</testResource>
</testResources>
What can it be?
The mvn command fails because your deployment package doesn't contain the whole project. From the sound of things with the current deployment package you should be able to do what you want with this command:
- java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="src/test/java/cucumber/features" --glue cucumber.steps
--tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
Otherwise, if you want to use maven you'll need to zip up the whole project and include it's pom.xml. So for example using the sample cucumber java tests
git clone https://github.com/aws-samples/aws-device-farm-appium-cucumber-tests-for-sample-app.git
zip -r deployment_package.zip aws-device-farm-appium-cucumber-tests-for-sample-app
Then you should be able to use maven in the testspec.yml file. For example, I could run the following command for the sample: mvn clean test after going to the project dir and then to get the results I had to export the target directory.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app
- mvn clean test
...
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app/target
- $DEVICEFARM_LOG_DIR
However, you'll need to upload the zip file as an APPIUM_NODE test type to avoid the test package parser there.
HTH
-James

Eclipse Oxygen This compilation unit is not on build path of java project

I have created a Kafka Streams Project using Maven Archetype:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.kafka \
-DarchetypeArtifactId=streams-quickstart-java \
-DarchetypeVersion=1.0.0 \
-DgroupId=streams.examples \
-DartifactId=streams.examples \
-Dversion=0.1 \
-Dpackage=myapps
Compiling and running the program:
> mvn clean package
> mvn exec:java -Dexec.mainClass=myapps.Pipe
The program works fine.
However when I am editing the code and try Ctrl+Space I am getting Cannot perform operation error:
This compilation unit is not on build path of java project.
See the image below:
Just run
mvn eclipse:eclipse
in the project directory and refresh your project in eclipse: File -> Refresh

Unable to run Maven Commands on Docker as Non-root

I am building my project on docker (using docker-maven) and need to execute it as non-root.
From the official documentation, it seems that running maven as non-root is supported (https://github.com/carlossg/docker-maven#running-as-non-root).
So I run the following:
sudo docker run -v "$PWD":/var/maven -w /var/maven -ti -u 1000 -e MAVEN_CONFIG=/var/maven maven mvn package -Duser.home=/var/maven
where $PWD is my project root directory.
However, I always get permission related issue such as
Error while storing the mojo status: /var/maven/mymodule/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst (Permission denied)
or unable to delete some files if I run mvn clean package instead.
How do I run the command as non-root properly?

Maven not found while using Gitlab-ci-multi-runner

I've been trying to set up GitLab-CI to build Maven Java projects in Raspbian, but whenever It tries to run the build script it fails because it can't find Maven. I used this guide to install the runner.
Build trace:
Running with gitlab-ci-multi-runner 1.10.4 (b32125f)
WARNING: image is not supported by selected executor and shell
Using Shell executor...
Running on raspberrypi...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/f09314a8/0/RBian/TestProject'...
Checking out 54d2e140 as master...
Skipping Git submodules setup
$ mvn clean package
bash: line 22: mvn: command not found
ERROR: Build failed: exit status 1
.gitlab-ci.yml
image: maven:3-jdk-8
build:
script: "mvn clean package"
artifacts:
name: "TestProject"
paths:
- "target/*.jar"
Does anyone know what causes this?
EDIT: Modifying /etc/default to add $MAVEN_HOME/bin to $PATH did the trick.
Try adding MAVEN_HOME path into config.toml environment field.
environment = ["MAVEN_HOME=/path/to/maven"]

Categories

Resources