XPath 1.0 get tag with dot in the attribute name - xpath

I want to get <sonar.exclusions>, <jacoco.line.min.coverage> and <jacoco.complexity.min.coverage> from the pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.xxx.xxx/groupId>
<artifactId>yyyy</artifactId>
<version>zzzzz</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jacoco.complexity.min.coverage>1.0</jacoco.complexity.min.coverage>
<jacoco.line.min.coverage>1.0</jacoco.line.min.coverage>
<sonar.exclusions>jjjjjj.jjjjj.jjjjj.Jjjj</sonar.exclusions>
</properties>
I don't know how get the value in the attributes with a dot in their in name in xPath 1.0.
Thanks.

This XPath will give it:
"//*[local-name()='sonar.exclusions' or local-name()='jacoco.line.min.coverage' or local-name()='jacoco.complexity.min.coverage']"
Tested on http://xpather.com/ The result is correct

Related

Maven error reguarding war files & pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my.ssat</groupId>
<artifactId>myssatProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>myweb</artifactId>
<packaging>war</packaging>
<name>myweb</name>
</project>
Cannot access default field of properties
web.xml is missing and is set to true.
I am getting these errors whenever I create maven module in (war) format

How to create Multi-Module project on Maven?

I am trying to make a new multi-module Spring project with Maven. I have one main Pom.xml, and to other modules.
This is the main pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ev</groupId>
<artifactId>multi</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>main</module>
<module>user</module>
</modules>
And this is the module1 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>multi</artifactId>
<groupId>org.ev</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>user</artifactId>
</project>
Where should i add the dependencies? When i put them into main pom.xml , i get an error "cant resolve pom" .
Do you have any idea about this issue? Because its very hard to create multi module project for me.
try to change main/pom.xml
<artifactId>multi</artifactId>
to
<artifactId>main</artifactId>

What tags are really required or recommended when using packaging type pom in Maven?

Once you set packaging equal to pom, do you need the groupID, artifactId and version tags and if so, what purpose do they serve? Are there any tags you should use (after all groupID is clearly intended for java so I wouldn't be surprised if there are other language or artifact type specific tags that should be used). Samples:
Simple parent pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.company</groupId>
<artifactId>project_name</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<modules>
<module>hosts</module>
</modules>
</project>
Simple child pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.company</groupId>
<artifactId>hosts</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Then sub children are various projects of many types, java, C++, angular, python, more poms.
You need all those tags.
The POMs are deployed along with the JARs, WARs etc. with their respective Maven coordinates (GroupId, ArtifactId, Version). They are resolved if anybody uses e.g. a dependency with your parent.

Versions Maven Plugin update-parent checks online maven

I have 2 maven projects in- parent and child, both having 0.0.1-SNAPSHOT.
The pom of parent:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tmn</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
The pom of child:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tmn</groupId>
<artifactId>child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.tmn</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>child</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I updated the version of the parent pom to some release version, say 1.0.0 and did mvn clean install on my parent. So, my maven local repo contains the released pom. Now, I want to update the parent.version and the version of my child pom. I run
mvn versions:update-parent -DparentVersion=1.0.0 -DgenerateBackupPoms=false -Dmaven.repo.local=/path/to/repo
I want it to blindly update the parent.version to the parentversion I supply in my command. But I get this WARNING and it is not updated.
artifact com.tmn:parent: checking for updates
[WARNING] Not updating version: could not resolve any versions
There is a similar issue logged here but I didn't understand the solution to this: https://github.com/mojohaus/versions-maven-plugin/issues/121

Maven insist using local parent rather than remote WITHOUT relativePath mentioned

I have a test project which is based on a parent project. This parent is build beforehand and is available on local artifactory server. The parent project is not available locally and this should stay this way.
As you see I am not using the relativePath element.
Still, when running "mvn clean install -U" I get an error about missing parent.
[ERROR] Non-resolvable parent POM for com.test.example:test:0.0.1-SNAPSHOT: Could not find artifact com.test:projects-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 6, column 10 -> [Help 2]
The test project pom.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.example</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
...
</dependencies>
<build>
...
</build>
</project>
Here is the parent pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
According to this, the default value for <relativePath> is ../pom.xml, so Maven will look locally first.
If you want to force the lookup to occur in your repository manager, use this trick:
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!— This forces a lookup against the repo —>
</parent>

Resources