I've a Springboot project handled by maven that contains some secrets encrypted with Jasypt. When I'm running the mvn deploy I'm passing the jasypt password as:
mvn -B clean deploy -Djasypt.encryptor.password=${jasypt_password}
And it is able to run test cases and deploy the jar file to repository. But when I'm doing the same with mvn release the jasypt password is not properly set.
mvn -B clean release:prepare release:perform -Djasypt.encryptor.password=${jasypt_password}
Or
mvn -B release:prepare -Djasypt.encryptor.password=${jasypt_password}
For both these cases, I'm getting following error while running the test cases.
Caused by: java.lang.IllegalStateException: Required Encryption configuration property missing: jasypt.encryptor.password
The plugin configuration I'm using is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<localCheckout>true</localCheckout>
</configuration>
</plugin>
How should I set jasypt password while running the maven release?
I got the issue solved using following command. Apparently maven release plugin takes configuration parameters in a different way.
mvn -B clean release:prepare release:perform -Darguments="-Djasypt.encryptor.password=${jasypt_password}"
You can check this link which gives more details about the issue.
Basically it states that
Once you enable jasypt-spring-boot the password property is required
as specified in the documentation
They have suggested multiple solutions. One of them being:
Add jasypt.encryptor.password=dummy to your springboot properties file.
And another (if running from command line), run your jar with
-Djasypt.encryptor.password=*******************
If you are using Intellij,
Using
-Djasypt.encryptor.password=${jasypt_password} as Project argument should resolve your issue.
If it doesnot help then try
--jasypt.encryptor.password=${jasypt_password}.
Let me know if this helps.
Thanks,
Manu
Related
I am running Maven Checkstyle plugin through pre-commit githook written in python (I think that the same question applies to running it directly from terminal).
The command is:
mvn checkstyle:checkstyle
However, I would like to run Maven Checkstyle only on files modified by git. For instance, I could run it once for each file. If I want to run it on a specific file, I may define the following pattern (I am not sure why do I need the pattern of stars and dashes in front):
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/*File.java
However, I am not able to pass file path and file name, for instance:
mvn checkstyle:checkstyle -Dcheckstyle.includes=src/main/java/File.java
Or, following the above mentioned pattern:
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/*src/main/java/File.java
I have tried many other combinations as well, but nothing works. I found this issue which is about the same thing, so I am wondering if someone has found a solution to this.
I have also read:
How to run maven checkstyle plugin on incremental code only
Is there a maven-git-checkstyle plugin that runs checkstyle goal on git staged files alone?
How to check style arbitrary list of java files from command line?
but they do not solve my problem.
There is an example here: github project of maven-checkstyle-plugin
Put a placeholder in pom and pass the parameter by maven command line.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<includes>${checkstyle.includes}</includes>
</configuration>
Command line: mvn checkstyle:check "-Dcheckstyle.includes=**/File.java"
I can make the Azure ops pipeline but my question is I have checkedin my code into repository where we should not checkin the application property file.
That means on the deployment time i should have to download the application property file from some secure place and build my spring boot app before i deploy into app engine right.
So, what i did so far is, I downloaded my application property file into azure agent at run time. I passed the property file into maven build command but it did not work out. [Note: I already searched a lot read a lot of answers and applied as well but nothing worked]
Command line I used:
mvn -f myapp-springboot-api/pom.xml
-Dspring-boot.run.jvmArguments="-Dspring.config.location=file:/home/username/application.properties"
clean package appengine:deploy
I also tried with
mvn -f myapp-springboot-api/pom.xml
--spring.config.location=file:/home/username/application.properties
clean package appengine:deploy
This also did not workout.
Also, I tried passing the whole property file location via pom.xml
pom.xml changes:
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>1.1.1.RELEASE</spring-cloud.version>
<property.file.location>${property.file.location}</property.file.location>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<files>
<file>${property.file.location}</file>
</files>
</configuration>
</plugins>
</build>
Than I tried to build with:
mvn -f myapp-springboot-api/pom.xml
-Dproperty.file.location="/home/username/application.properties" clean package appengine:deploy
Than also I was not able to load the define external property file.
Thanks in advance, please help your help is highly appreciated.
The commands you are using won't actually pass the external properties files to the application engine (As it exists on a different server) and would only be scoped to the running maven process that is packaging + deploying.
So if you have copied your property file onto the external agent before building I would just replace the default one you have checked into source control.
So your build steps would be for example:
Download property file
Overlay:
mv /home/username/application.properties myapp-springboot-api/src/main/resources/application.properties
Build + Deploy
mvn -f myapp-springboot-api/pom.xml clean package appengine:deploy
So now your compiled and deployed jar file would include your new properties file, an alternative that recently came out would be to use something like Azure App Configuration.
If you want to not have to do another command you could also use the Maven Resources Plugin to perform the copy for you.
In my pom.xml of com.test:Service:1.0, I have a dependency on some local jar: com.test:Parser:1.0
I want to resolve all dependencies except for it, since I install it manually to my local maven. Resolve command:
mvn -B dependency:resolve -DincludeParents=true
But it fails on:
[ERROR] Failed to execute goal on project Service: Could not resolve
dependencies for project com.test:Service:jar:1.0: Could not find
artifact com.test:Parser:jar:1.0 in central
(https://repo.maven.apache.org/maven2)
Then I tried to add the options
-DexcludeGroupIds=com.test -DexcludeArtifactIds=Parser
but am still getting the same error. Am I misusing the options?
Reference: http://maven.apache.org/plugins/maven-dependency-plugin/resolve-mojo.html
I'm using 3.8.6 and it looks like go-offline works with exclude*, but resolve does not:
mvn dependency:go-offline -DexcludeGroupIds=com.test
According to: https://maven.apache.org/plugins/maven-dependency-plugin/index.html
dependency:go-offline tells Maven to resolve everything this project is dependent on (dependencies, plugins, reports) in preparation for going offline.
dependency:resolve tells Maven to resolve all dependencies and displays the version.
This seems to simply be a bug. See
https://issues.apache.org/jira/browse/MDEP-568
https://github.com/apache/maven-dependency-plugin/pull/2
The solution, as proposed in the above threads, is to use a different library: https://github.com/qaware/go-offline-maven-plugin
In your pom.xml add the plugin:
<plugin>
<groupId>de.qaware.maven</groupId>
<artifactId>go-offline-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<dynamicDependencies>
</dynamicDependencies>
</configuration>
</plugin>
Then use the command mvn de.qaware.maven:go-offline-maven-plugin:resolve-dependencies with the required options.
We have a private repository at work so once a while we need to download artifacts from the central repository and upload them.
Someone wrote a program a while ago for that which didn't always work perfectly: it would download all dependencies for each artifact separately, it would first scan the dependency tree and only then download them, it wouldn't download sources and javadocs, was slow, etc.
Recently I have come across this useful maven plugin called dependency and its goal get.
So now to download some artifact, let's say for instance com.sparkjava.spark-core:2.5.4, I would type on my terminal:
mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4
mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4:sources
mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4:javadoc
Which would download the artifact along with all its dependencies to the directory ~/.m2/repository which I can later transfer to our private repository.
This method works good but has 2 problems:
I have to run the command 3 times when each time the classifier is different and I would like to get all classifiers at once.
It always downloads the artifacts into ~/.m2/repository, which can sometime contain other artifacts I'm not intrested in having on the private repository. I need be able to choose another directory destination.
What can I do about these issues? About the first one I can work it around with an alias (which will still run the same command 3 times) but I have no idea what to do about the second issue and it's not mentioned on the plugin's documentation either.
To solve (2), you can update the settings.xml with a tag
<localRepository>C:\Users\my\custom\existing\directory</localRepository>
and make sure when you are building the project, the same settings.xml looked into which can be done using
mvn clean install -gs <pathToDirectory>
Note - Please modify the path accordingly.
To solve (1), adding the following to settings.xml should work as well -
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
Source - Maven – Always download sources and javadocs
Other maven command that could help here is -
resolve command with classifier :
mvn dependency:resolve -Dclassifier=javadoc #downloads all the documentation
I don't get it. I've set up my pom.xml to use the Maven exec plugin so I can execute some of the classes in my project with the correct classpath, -D defines and -javaagent. So from a shell with the classes built in ./target/classes etc.. I can run the main() methods using
mvn exec:java -Dexec:mainClass=classWithAMainMethod
All good so far.
Now I want to ship my project(a jar artifact) and I still want to be able to use the configuration I've put in the pom.xml for running the classes with the correct arguments etc.. How do I do it? Is there some way of staying
mvn -artifactJar=MyArtifact.jar exec:java -Dexec:mainClass=classWithAMainMethod
when all I have is MyArtifact.jar(Or a maven repository with MyArtifact.jar in it)??
I've tried the following:
Get the jar with the dependency:get goal and unzip it. I can't do anything with it
as the pom.xml seems to end up in META-INF/maven in the artifact jar. Is there any way of using it?
Creating a dummy pom where I want to run my project with a single dependency on my projects artifact. I can then use exec:java to run the main classes but it's dosen't uses the configuration from my projects pom.
Thanks.
The AppAssembler plugin worked out quite well for me. I replaced the exec plugin config in my project's pom with something like this in the build section:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
<extraJvmArguments>
-Djava.rmi.server.hostname=localhost
-javaagent:${spring.javaagent.jar}
</extraJvmArguments>
<programs>
<program>
<name>foo1</name>
<mainClass>net.foor.FooMain</mainClass>
</program>
...
</configuration>
</plugin>
In Eclipse I created an external tools launcher to run the resulting scripts from target/appassembler/bin
On the machine I wanted to deploy to(Assuming access to the internal Maven repository where my artifact+dependencies have been installed/deployed):
First use wget or mvn dependency:get to get a copy of my artifact jar.
Extract the pom. unzip -j artifact.jar */pom.xml*
Run mvn appassembler:assemble -DassembleDirectory=.
Move the artifact.jar into the ./lib directory
Set execute permissions on generated shell scripts in ./bin
Have you tried using something like onejar?
That sounds like what you're looking for.