I have a question regarding the maven checkstyle plugin. The problem is that it creates an output file and fails because that file does end with new line (which the plugin is supposed to check for):
[ERROR] target/checkstyle-result.xml:[0] (misc) NewlineAtEndOfFile: File does not end with a newline.
I tried to exclude the target directory from that plugin with:
<properties>
<checkstyle.excludes>**/target/**</checkstyle.excludes>
</properties>
but that does not do anything.
The plugin itself is configured in the parent pom.xml file, so I don't have any control over it.
Any suggestions?
I had the same problem and figured it out. The problems with your rule (and mine before) are the following:
**/target/** does not match the file target/checkstyle-result.xml. A better approach would be **/target/**/*
Since your XML is not source code but a resource, you should use the checkstyle.resourceExcludes property instead.
Related
So this problem is vexing me and I decided to ask a question because no answer out there was able to help, the problem is happening SPECIFICALLY to project.build.directory.
I have a Jenkins pipeline, and I need to build this string to deploy my artifact
#${project.build.directory}\${project.artifactId}_${project.version}.car
I am using the following to get some information from the pom.xml
script {
pom = readMavenPom file: 'pom.xml'
deployVersion = pom.properties.'deploy.version'}
So doing both
${deployVersion} and ${pom.version}
works perfectly, so there's no reason for ${pom.build.directory} not to work, but it doesn't. Nevertheless I decided to work around it and expose that property via the pom's properties, since I know the property works inside the pom, so I did, in my pom
<properties>
<build.dir>${project.build.directory}</build.dir>
</properties>
And that don't work either, after assigning pom.properties.'build.dir' to buildDir I get ${project.build.directory} as a literal
#${buildDir}\${pom.artifactId}_${pom.version}.car
I have no idea why this is happening or how to fix. Any ideas?
EDIT: The below was answered in the comments, either escape with another slash (\\) or use a forward slash (didn't test this one though)
Even more weird, the \ disapears and it don't convert pom.artifactId (which will convert properly if I call it without the build directory)
I tried to add custom jar into my project (to pom.xml). When I made an operation
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> -DartifactId=<myArtifactId> -Dversion=<myVersion> -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
I actually received an error: the specified file not exists. But the file is in the folder - that's the problem. How I can resolve this? Or how I can add custom jar without this step? I know about scope , but it's not working properly - maven variable ${basedir} cannot be used in systemPath.
Maven 3.3.9
UPDATE 1: Actually, now I find smth new: Maven doesn't like dots in groupId and version. After some tries I installed file, but it's wrong path, because instead of (e.g) org.my.local.file tree I received file in org_my_local_file folder in maven repo.
I did this many times and it worked as expected.
What do you exactly mean with :
Maven doesn't like dots in groupId and version.
What exception do you get ?
You get org_my_local_file because I think you exachanged '.' in the groupId against '_' ?
You find a good tutorial here where you can see how it is done correctly :
How to include custom library into maven local repository?
EDIT :
It looks like you are using windows. Especially powershell is known to cause problems. Have a look here, may be you have to escape some characters, there are some possible solutions :
install maven artifact
I encountered this issue when trying to initialize our base development environment. We use an Ant script to initialize Maven, our developer server and other tools and includes installing a few 3rd party jars into the local Maven repository. This error, "The specified file '<path>\true' not exists" was occurring when invoking Maven from within Ant 1.9.11.
I also used this answer to specify paths identified in the Ant script and set them in the batch script template before running the batch script.
Specifically, this answer offered a lot to get the batch script constructed: https://stackoverflow.com/a/36298099/2336934. Didn't take much:
<!-- generate the batch file -->
<tempfile property="temp.file" suffix=".properties" deleteonexit="true" destdir="${env.TEMP}" />
<echoproperties destfile="${temp.file}" />
<replaceregexp file="${temp.file}" match="([^=]*)=" replace="#\1#=" byline="true" />
<copy file="${basedir}/scripts/install-jars.template" tofile="${basedir}/scripts/install-jars.bat" />
<replace file="${basedir}/scripts/install-jars.bat" replacefilterfile="${temp.file}" />
<echo message="Running batch file for Maven setup" />
<exec executable="${basedir}/scripts/install-jars.bat" />
<delete file="${basedir}/scripts/install-jars.bat" deleteonexit="true" />
There weren't any issues with the parameters being passed, but this must be specified correctly. Running the command you're trying to execute in a script temporarily in a command window is useful to verify the command syntax and function before trying to embed in a script.
I even created a empty true file to satisfy the error which complained the file was not a valid POM file. Filling it with basic POM content led to another error. So reader beware, this business about "true not exists" is a Red Herring.
Moving the Maven install:install-file commands out to the batch file was the key to get past the issue. It also allowed me to specify the quotes in the command as " rather than " due to the commands originally being specified in the Ant script (xml).
I need to rename set of files in maven without using Maven-Antrun-plugin in a single execution or command.
I have many property files with same suffix ab_bc.properties,de_bc.properties,etc and I need to replace the suffix to some other name like ab_BR.properties,de_BR.properties.
Is there any plugin available to do the same in Maven?
I tried Maven-assmbly plugin and copy-rename plugin but adding lot of files makes it more complex.
You can give this plugin a try or have a look on workarounds with the Maven Assembly plugin, see related question here.
Hope that helps :)
Can anyone please help on this, if this is feasible , I am trying to fetch the main ${project.version} value form the external property file , Is this possible to load if yes can you please suggest
here is one of the example,
version. Properties contains this value
theme.version=1.1.1-snapshot
My Pom.xml cantains the references of this version.
<parent><groupId>--</groupId>
<artifactId>theme</artifactId>
<version>${theme.version}</version></parent>
If I do mvn clean install I want my repository war file to be updated with the theme.version as 1.1.1-snapshot. Basically I meant not to update my POM.xml with any versions numbers I want it to load everything from the properties file always
With the Maven assembly plugin I know I can set the permissions of the files contained within my tar such as here. However can I use the plugin to set the permissions of the tar itself?
Maybe I should just the ant plugin but this is a little messy
I haven't tested this, but you might be able to use "exec-maven-plugin" to do this.
How to change permission of jar packaged by maven? I am using maven assembly plugin
"Use maven:exec plugin to execute chmod"
So the idea is that you would add another plugin to the pom.xml file that sets the permission on the tar itself.
The only drawback that I see is that you have to have the name of the file in the plugin xml code in the pom file. That's fine as I have that listed in in the maven-assembly-plugin. But the file extension is found in assembly.xml (.zip, or .tar-gz), so if you change the file extension in assembly.xml, you would have to remember to change it in the pom.xml file. Not a big hassle, but it might be easy to miss on your first review.