Hi Stephen,
it is allowed to manually override the version in a child project.
This does not defeat the point of depMgmt, in my opinion. So why should
the versions-maven-plugin should be able to do it, too?
We have a parent pom with "official" versions but want to build child
projects with "unofficial" versions. This is where we want to override
the version in the child pom.
I am searching for a solution for a build pipeline where a project A is
build using the latest version of project B. Perhaps I can achieve what
I want by using some kind of "unofficial" parent pom whose versions are
updated as you suggested. I will see.
I tried to patch your plugin such that it is able to add a version
element to the pom. Perhaps you'll want to use it if you change your mind.
Thanks for your answers.
Best regards
Achim
On 22.05.2012 16:28, Stephen Connolly wrote:
> The guiding principal is that only explicit versions are modified. If
> it introduced an override into project A then that would defeat the
> point of depMgmt in P.
>
> If you run the plugin on project P's pom, it will process the deps and
> the depMgmt by default, i.e. see
>
>
> http://mojo.codehaus.org/versions-maven-plugin/use-latest-versions-mojo.html#processDependencyManagement
>
> -Stephen
>
> On 22 May 2012 14:32, Achim Abeling <[email protected]> wrote:
>> Is there a reason why the plugin cannot update versions from managed
>> dependencies?
>>
>> If I have to define a version in my project A for dependency B the
>> dependencyManagement in my parent pom gets rather useless, isn't it?
>>
>> Best regards
>> Achim
>>
>> On 22.05.2012 13:54, Stephen Connolly wrote:
>>> If you don't specify the version in the pom you are running on, then
>>> it will not add the version.
>>>
>>> If you run against the P pom then it will update that one
>>>
>>> On 22 May 2012 11:36, Achim Abeling <[email protected]> wrote:
>>>> Hi,
>>>>
>>>> we have the following scenario:
>>>>
>>>> - project A has project P with version 1 as parent.
>>>> - project P in version 1 defines project B with version 1 in it's
>>>> dependencyManagement section.
>>>> - project A has project B as dependency without defining the version and
>>>> therefore inherits the version from the parent project P
>>>>
>>>> Normally, project A uses version 1 of project B.
>>>>
>>>> Now, there are newer versions of project B in the repository, say version
>>>> 2.
>>>>
>>>> Using
>>>> # mvn versions:display-dependency-updates
>>>> on project A correctly says something like
>>>>
>>>> [INFO] The following dependencies in Dependency Management have newer
>>>> versions:
>>>> ...
>>>> [INFO] project B ..................... 1 -> 2
>>>>
>>>> But calling
>>>> # mvn versions:use-latest-versions
>>>> does not change the pom.xml.
>>>>
>>>> I would expect the versions-plugin to add
>>>> <version>2</version>
>>>> to the dependency definition for project B.
>>>>
>>>> What can I do?
>>>>
>>>>
>>>> Thanks
>>>> Achim
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>> http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Index: src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java
===================================================================
--- src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java (Revision 16684)
+++ src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java (Arbeitskopie)
@@ -5,7 +5,10 @@
import org.codehaus.stax2.XMLInputFactory2;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
import java.io.File;
+import java.io.IOException;
import java.net.URL;
/**
@@ -118,4 +121,37 @@
}
+ public void test_setDependencyVersionWithoutVersionElement()
+ throws XMLStreamException, IOException
+ {
+ URL url = getClass().getResource( "PomHelperTest.testSetDependencyVersion.pom.xml" );
+ StringBuffer input = PomHelper.readXmlFile( new File( url.getPath() ) );
+
+ XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
+ inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
+
+ ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory );
+
+ boolean result = PomHelper.setDependencyVersion(pom, "org.codehaus.mojo", "test", "1", "2");
+ assertTrue(result);
+
+ System.out.println(pom.asStringBuffer());
+ }
+
+ public void test_setDependencyVersionWithVersionElement()
+ throws XMLStreamException, IOException
+ {
+ URL url = getClass().getResource( "PomHelperTest.testSetDependencyVersion2.pom.xml" );
+ StringBuffer input = PomHelper.readXmlFile( new File( url.getPath() ) );
+
+ XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
+ inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
+
+ ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory );
+
+ boolean result = PomHelper.setDependencyVersion(pom, "org.codehaus.mojo", "test", "1", "2");
+ assertTrue(result);
+
+ System.out.println(pom.asStringBuffer());
+ }
}
Index: src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion.pom.xml
===================================================================
--- src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion.pom.xml (Revision 0)
+++ src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion.pom.xml (Revision 0)
@@ -0,0 +1,24 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <!--parent>
+ <groupId>org.myorg</groupId>
+ <artifactId>myorg-parent</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </parent-->
+ <groupId>localhost</groupId>
+ <artifactId>it-set-004</artifactId>
+ <packaging>jar</packaging>
+ <version>${V1234567890123456789012}</version>
+ <name>set version for pom with no dependencies</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>test</artifactId>
+<!-- <version>1</version> -->
+ </dependency>
+ </dependencies>
+
+</project>
Index: src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion2.pom.xml
===================================================================
--- src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion2.pom.xml (Revision 0)
+++ src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.testSetDependencyVersion2.pom.xml (Revision 0)
@@ -0,0 +1,24 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <!--parent>
+ <groupId>org.myorg</groupId>
+ <artifactId>myorg-parent</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </parent-->
+ <groupId>localhost</groupId>
+ <artifactId>it-set-004</artifactId>
+ <packaging>jar</packaging>
+ <version>${V1234567890123456789012}</version>
+ <name>set version for pom with no dependencies</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>test</artifactId>
+ <version>1</version>
+ </dependency>
+ </dependencies>
+
+</project>
Index: src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
===================================================================
--- src/main/java/org/codehaus/mojo/versions/api/PomHelper.java (Revision 16684)
+++ src/main/java/org/codehaus/mojo/versions/api/PomHelper.java (Arbeitskopie)
@@ -515,6 +515,8 @@
haveGroupId = false;
haveArtifactId = false;
haveOldVersion = false;
+
+ pom.mark(2);
}
else if ( inMatchScope && matchTargetRegex.matcher( path ).matches() )
{
@@ -555,11 +557,20 @@
}
else if ( matchScopeRegex.matcher( path ).matches() )
{
+ pom.mark(3);
+
if ( inMatchScope && pom.hasMark( 0 ) && pom.hasMark( 1 ) && haveGroupId && haveArtifactId &&
haveOldVersion )
{
pom.replaceBetween( 0, 1, newVersion );
madeReplacement = true;
+ } else if (pom.hasMark(2) && pom.hasMark(3)) {
+ /* no version element found */
+ String oldContent = pom.getBetween(2, 3);
+ String newContent = oldContent
+ + "<version>" + newVersion + "</version>";
+ pom.replaceBetween(2, 3, newContent);
+ madeReplacement = true;
}
pom.clearMark( 0 );
pom.clearMark( 1 );
Index: src/main/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReader.java
===================================================================
--- src/main/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReader.java (Revision 16684)
+++ src/main/java/org/codehaus/mojo/versions/rewriting/ModifiedPomXMLEventReader.java (Arbeitskopie)
@@ -47,7 +47,7 @@
/**
* Field MAX_MARKS
*/
- private static final int MAX_MARKS = 3;
+ private static final int MAX_MARKS = 4;
/**
* Field pom
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email