What's the recommended way of updating maven repository metadata - maven-2

I'll like to know, what's the recommended way of updating maven repository metadata?
The scenario I'm working with is such that the content of maven-cargo plugin metadata is stale and does not reflect an updated repository metadata, hence, my reason to change it.
For example, I have this in maven-metadata-central.xml for the maven-cargo plugin:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-cargo-plugin</artifactId>
</metadata>
Whereas the updated version should be this:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
</metadata>
How do I go about this?
Thanks

Add below into settings.xml (This makes maven to use the specified group first.
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
<pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>
And add below into your pom.xml
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
</container>
</configuration>
see http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html

Related

Element faces-config must be declared

I've got this error in project faces-config.xml file in my IntelliJ IDE:
Element faces-config must be declared
Here is my faces-config.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
version="2.3">
</faces-config>
And pom.xml file:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
How can I fix this?
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
Try opening http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd in your favorite webbrowser. It returns 404. In other words, this URL is not correct. The IDE's built-in XML parser is also struggling this way. It cannot find the declaration of <faces-config> root element there.
It's not clear which JSF version exactly you intend to develop with. If it's 2.3, as indicated by version="2.3", then you should be using http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd instead, as specified in "Java EE 8 Schema Resources" section of the webpage behind http://xmlns.jcp.org/xml/ns/javaee.
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
But if it's indeed 3.0, the first Jakartified version (i.e. you should be using jakarta.* package for Jakarta EE API over all place instead of javax.* package), then you should be using the following deployment descriptor root declaration as specified in "Jakarta EE 9" section of the webpage behind https://jakarta.ee/xml/ns/jakartaee.
<faces-config
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
version="3.0">
See also:
Jakarta Faces 4.0 specification - 11.3.5 Application Configuration Resource Format

Maven using $${...} for literal instead of actual property value does not work

I have a pom.xml and using ant-run plugin I am trying to replace following in my pom.xml;
From:
<version>${current.build.version}</version>
To:
<version>DEV.0.0-SNAPSHOT</version>
I tried the same with google replacer plugin as well as now maven-ant run plugin both resolves into actual value of the property instead of the literal.
Full POM.xml is as follows;
<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>x.y.z</groupId>
<artifactId>parent</artifactId>
<version>${current.build.version}</version>
</parent>
<properties>
<!-- Build Version for Entire Stream -->
<current.build.version>DEV.0.0-SNAPSHOT</current.build.version>
<!-- Replacement property while installing poms for child projects -->
<parent.version.property.name>current.build.version</parent.version.property.name>
</properties>
<artifactId>child</artifactId>
<version>${current.build.version}</version>
<packaging>jar</packaging>
<build>
<plugins>
<!-- Replace parent version from property to actual version just before install -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Replace parent version if its a property to respective version -->
<execution>
<id>replace-parent-property-to-version</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target name="replace-parent-property-to-version">
<!-- Get some Ant-Contrib task def -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath refid="maven.plugin.classpath" />
</taskdef>
<!-- Copy original file to temp location first -->
<var name="orig.project.file" value="${basedir}/pom.xml" />
<var name="temp.project.file.name" value="versioned-pom.xml" />
<var name="temp.project.file" value="${project.build.directory}/${temp.project.file.name}" />
<copy file="${orig.project.file}" tofile="${temp.project.file}" />
<!-- Replace the parent version from property to actual value -->
<var name="dollar" value="$${" />
<var name="curlBrace" value="}" />
<var name="var.parent.version.property.name" value="${dollar}${parent.version.property.name}${curlBrace}" />
<replace file="${temp.project.file}" token="<version>${var.parent.version.property.name}</version>"
value="<version>${project.version}</version>" />
<!-- Now overwrite project file property with update temp file for release -->
<var name="project.file" unset="true" />
<property name="project.file" value="${temp.project.file}" />
<echo message="Parent version updated for release in file ${project.file}..." />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you see my configuration I already $$ which also resolves into property value instead of ${...}. I am unable to solve this.
Also is there a property in maven form which I can access pom.xml file location. I found in the document its called project.file but I am unable to access it in ant-run plugin. Its says not set.
You should not do that, it is an anti-pattern. I'm sure you already see the Warning from Maven when you try to build.
It might be tempting to do it like that but it results in non-repeatable builds, so it is discouraged. You should instead always keep a literal (e.g. "DEV.1.0-SNAPSHOT") value there and update its value with the maven versions plugin instead.
If you only have one version for the whole project, and the parent doubles as a module pom (another common -but tolerated- antipattern), you can declare the parent's version in its pom, the version of the parent again in the parent section of any children and skip the child version. This way you execute
mvn versions:set -DnewVersion=DEV.1.0
on the module project when it's time to release.
You commit, do the release, then execute
mvn versions:set -DnewVersion=DEV.1.1-SNAPSHOT
to resume development..

Converting a Maven 1 project into Maven 2

I'm new to Maven, and have been running into some difficulty in a project. I am to convert a Maven 1 project into Maven 2.
I started with these files:
maven.xml -- contains custom build scripts
project.properties -- general build settings
project.xml -- Project Object Model (POM) definition
From my understanding, Maven 2 project I must move these files into these:
pom.xml -- POM definition
(and possibly) settings.xml -- local configuration
I have gone about this by using the command 'mvn one:convert'.
This seemed to take care of project.xml > pom.xml
I then added a to pom.xml to include project.properties (which seemed to work).
Am I right in assuming that all I have left is to transfer over the contents of maven.xml >> pom.xml ?
maven.xml starts with:
<project default="site_deploy"
xmlns:ant="jelly:ant"
xmlns:maven="jelly:maven"
xmlns:j="jelly:core"
xmlns:util="jelly:util">
<ant:property environment="env"/>
and contains contains goals such as:
<goal name="site_deploy">
<attainGoal name="clean"/>
<attainGoal name="clean:clean"/>
<ant:delete dir="${maven.src.dir}/core/target" />
<attainGoal name="core_deploy"/>
</goal>
<goal name="core">
<maven:maven
descriptor="core/project.xml"
goals="jar:install"/>
<ant:property name="m2Dir" value="${maven.repo.local}/../../.m2/repository/app/${application.version}"/>
<ant:property name="m1Path" value="${maven.repo.local}/${application.id}/jars/${application.id}-core-${application.version}.jar"/>
<ant:echo message="copying jar m1 to m2 (${m1Path}) to (${m2Dir})" />
<ant:mkdir dir="${m2Dir}"/>
<ant:copy todir="${m2Dir}" file="${m1Path}" />
</goal>
From my reading if not bound to any build phase, goals can be executed outside of the build lifecycle by direct invocation, the second way being to write plugins for the goals.
How would I identify if the goals have dependencies-- how would I go about writing a plug-in? I've been referring mostly to the maven guides on apache.org, but some of it is hard to follow.
Here is the pom file generated:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>${application.id}</groupId>
<artifactId>${application.artifact}</artifactId>
<version>${application.version}</version>
<name>${application.name}</name>
<inceptionYear>2007</inceptionYear>
<organization>
<name>OrganizationName</name>
<url>http://organization.url</url>
</organization>
<scm>
<connection>scm:svn:connection</connection>
<url>http://svn.organization.local/svn/trunk/application_name</url>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-changes-plugin</artifactId>
<configuration>
<xmlPath>${basedir}/xdocs/changes.xml</xmlPath>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

Additional context for tomcat:run goal

How do I add an additional directory based context to a tomcat:run configuration?
I have the following jetty plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextHandlers>
<contextHandler implementation="org.mortbay.jetty.handler.ContextHandler">
<contextPath>/media/data</contextPath>
<resourceBase>/somedir/media/data</resourceBase>
<handler implementation="org.mortbay.jetty.handler.ResourceHandler" />
</contextHandler>
</contextHandlers>
<contextPath>/</contextPath>
<webAppSourceDirectory>foo-project/target/foo-webapp</webAppSourceDirectory>
...
</configuration>
</plugin>
</plugins>
...
</build>
How do I do this with tomcat:run?
I have a context.xml file in the tomcatconf dir
<?xml version='1.0' encoding='utf-8'?>
<Context path="/media" docBase="/somedir/media"/>
but this seems to get ignored.
I've also tried to explicitly set the contextFile parameter in the plugin configuration, but to no avail.
Reference:
http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html
have a look at the deployment description of the tomcat plugin.
Place the context.xml file to the default location
src/main/webapp/META-INF/context.xml
or use tomcat:run with a contextFile property on the commandline
mvn tomcat:run -DcontextFile="<path-to-your-context.xml-file>"

Maven Assembly Plugin - install the created assembly

I have a project that simply consists of files. I want to package those files into a zip and store them in a maven repository. I have the assembly plugin configured to build the zip file and that part works just fine, but I cannot seem to figure out how to install the zip file?
Also, if I want to use this assembly in another artifact, how would I do that? I am intending on calling dependency:unpack, but I don't have an artifact in the repository to unpack.
How can I get a zip file to be in my repository so that I may re-use it in another artifact?
parent pom
<build>
<plugins>
<plugin>
<!--<groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<filters>
<filter></filter>
</filters>
<descriptors>
<descriptor>../packaging.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
Child POM
<parent>
<groupId>com. ... .virtualHost</groupId>
<artifactId>pom</artifactId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Virtual Host - ***</name>
<groupId>com. ... .virtualHost</groupId>
<artifactId>***</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
I filtered the name out. Is this POM correct? I just want to bundle files for a particular virtual host together.
Thanks,
Walter
I have the assembly plugin configured to build the zip file and that part works just fine, but I cannot seem to figure out how to install the zip file?
Well, the created assembly should get automatically attached to the project and then uploaded into the repository on an install and deploy goal. Can you show your pom?
Update: With your current configuration, I don't think that the assembly gets created as part of your build. You need to bind the single goal to a lifecycle phase, typically package:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>../packaging.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
And now it should get installed/deployed properly.
Also, if I want to use this assembly in another artifact, how would I do that? I am intending on calling dependency:unpack, but I don't have an artifact in the repository to unpack.
You can declare a dependency on an assembly (using the right classifier and type in your case) but since dependency are resolved through the repository, you'll need to solve the first step first. Then, declare something like this (where the classifier is the assembly's id):
<dependency>
<groupId>com. ... .virtualHost</groupId>
<artifactId>***</artifactId>
<version>0.0.1</version>
<classifier>...</classifier>
<type>zip</type>
</dependency>
I think assemblies are supposed to be automatically attached to the build, but if that doesn't work, the Maven Build Helper "attach-artifact" goal attaches a specified file to be installed in the repository. I've used this plugin for installing files created by an external process like Ant or NSIS.
I don't know wether this could be usefull for you, but as a JAR file is basically a ZIP file plus the META-INF information, you could create your project as a jar without sources and add the xip countents in src/main/resources without needing any plugin configuration.
If you want your content to be in a different location, you can always do something like:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myzip</groupId>
<artifactId>myzip-artifact-id</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>false</filtering>
<directory>${basedir}/zipcontent</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</project>
I f you want your artifact to be installed and being accessible in a repository you will need to set it up for the deploy phase:
http://maven.apache.org/plugins/maven-deploy-plugin/usage.html