0

Is there a way to automatically get selenium-java version to update to the latest, in the POM file without having to manually change it?

I tried creating a selenium.version variable that can fetch a new update of selenium but my POM refuses to index the variable and it displays in red

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>${selenium.version}</version>
</dependency>

Any workaround?

Testilla
  • 602
  • 8
  • 21

3 Answers3

3

Honestly, the best way is to do exactly as you have done, with a property in your pom.xml defining ${selenium.version}, like this:

<properties>
    <selenium.version>3.8.1</selenium.version>
</properties>

A core principle of maven is reproducible builds. If you dont provide a concrete version number for your dependency (even a test dependency like selenium), then you risk the build of your project suddenly failing one day (or having some other inconsistency) when a new version of selenium is released.

You're better to define the version as 3.8.1, and if in future you see the need to upgrade (version 3.9.x... version 4.x...), just change the <property> and rebuild.

If multiple projects use selenium you can put the <property> in a parent pom which they all define as a parent.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156
2

If you want to automatically update the <version> property of the following dependency :

<dependency> 
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>3.8.1</version>
</dependency>

You can use the newVersion parameter within versions:update-property of Versions Maven Plugin as follows :

  • Versions 1.0 (included) to 2.0 (not included) :

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>[1.0,2.0)</version>
    </dependency>
    
  • Versions 1.0 to 2.0 (both included) :

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>[1.0,2.0]</version>
    </dependency>
    
  • Versions 1.5 and higher :

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>[1.5,)</version>
    </dependency>
    
  • Versions up to 1.0 (included) and 1.2 or higher :

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>(,1.0],[1.2,)</version>
    </dependency>
    
  • Version to be used exactly :

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>-DnewVersion=[3.8.0]</version>
    </dependency>
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

If you are using Maven 2, you can use the a version value of LATEST or RELEASE . LATEST refers to the latest released or snapshot version of a particular artifact, the most recently deployed artifact in a particular repository. RELEASE refers to the last non-snapshot release in the repository

   <dependency>             
        <groupId>org.seleniumhq.selenium</groupId>                              
        <artifactId>selenium-java</artifactId>                              
        <version>LATEST</version>                               
    </dependency>

But,Maven 3.x no longer supports usage of these metaversions in the POM. As a result, users will need to replace occurrences of these metaversions with a concrete version as there is a threat of non-reproducible builds imposed by automatic plugin version resolution.

https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes#Maven3.xCompatibilityNotes-AutomaticPluginVersionResolution

Sijin
  • 138
  • 9