maven icon indicating copy to clipboard operation
maven copied to clipboard

[MNG-7005] Support Gradle style GAV form for dependencies

Open jira-importer opened this issue 5 years ago • 13 comments

Chris Caspanello opened MNG-7005 and commented

 

I'm currently migrating a project from Gradle to Maven.  One thing that makes pom files so large is the typical 5 lines for a dependnecy.  It would be nice to be able to define the dependency similar to Gradle

Instead of :

<dependencies>
  <dependency>
    <groupId>myGroup</groupId>
    <artifactId>myArtifact</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>anotherGroup</groupId>
    <artifactId>anotherArtifact</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
</dependencies>

 

 

It would be less verbose to use a <gav> block like this:

 

<dependencies>
 <gav>myGruop:myArtifact:1.0.0-SNAPSHOT</gav>
 <gav>anotherGroup:anotherArtifact:1.0.0-SNAPSHOT</gav>
</dependencies>

 

I think an improvement like this would make Maven less verbose; one of the things that is attractive about Gradle.

I may be over simplifying this; but under the covers we'd just split the gav block on the semi colon and popoulate the existing dependency model.

 


1 votes, 4 watchers

jira-importer avatar Oct 23 '20 19:10 jira-importer

Michael Osipov commented

There is already a similar issue. This won't and cannot happen before version 4 or 5 with a model change. Moreover, you proposal does not scale, you cannot exclude transitive dependencies.

jira-importer avatar Oct 24 '20 20:10 jira-importer

Chris Caspanello commented

@Michael Osipov - I'm not suggesting we get rid of the typical <dependency> block; that can still be used to exclude certain transitivie dependencies.

I'm veiewing the <gav> tag as a simple shortcut. 

 

Optionally if you want to exclude all tranitive dependencies maybe you could add something like this <gav transitives="false">myGruop:myArtifact:1.0.0-SNAPSHOT</gav>  

It is still shorter and easier to read than <dependency>   <groupId>myGroup</groupId> <artifactId>myArtifact</artifactId> <version>1.0.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency>  

jira-importer avatar Oct 26 '20 11:10 jira-importer

Michael Osipov commented

Won't be really helpful.

jira-importer avatar Oct 26 '20 18:10 jira-importer

Chris Caspanello commented

Michael Osipov - Can you please elaborate why it won't be helpful?  I've got a few people on my team that would be interested in a (alternate) short hand way of defining dependencies.

jira-importer avatar Oct 26 '20 18:10 jira-importer

Michael Osipov commented

Supporting wildcard excludes all or nothing will not scale. People want/need to exclude selectively. Back to the topic, even if you consider is handy, pratical, etc. this is syntactical sugar and will likely lay around for years w/o being touched. Our resources are tight.

jira-importer avatar Oct 26 '20 19:10 jira-importer

Chris Caspanello commented

Michael Osipov - Like I said; this is an additive feature for shorthand.  Nothing prevents people from using the regular <dependency> block we all know and love

I can help contribute to this feature if you like

jira-importer avatar Oct 26 '20 19:10 jira-importer

Michael Osipov commented

Thank you for the offer, but believe me, this will require busload of changes and won't be accepted anytime soon.

jira-importer avatar Oct 26 '20 20:10 jira-importer

Delany commented

Dependencies are the busiest part of the pom and managing them is Maven's main job. I think you underestimate how much tedium it would save having a one line tag that matches command line arguments/log output.

Even if you retain the dependency tag for exclusions its still a big improvement.

<dependencies>
  <dependency>
    <gav>myGroup:myArtifact:1.0.0-SNAPSHOT:compile</gav>
  </dependency>
  <dependency>
   <gav>anotherGroup:anotherArtifact:1.0.0-SNAPSHOT:test</gav>
  </dependency>
</dependencies>

 

jira-importer avatar Oct 31 '20 13:10 jira-importer

Michael Osipov commented

There is an issue which proposes to use attributes. Please have a look.

jira-importer avatar Oct 31 '20 14:10 jira-importer

Delany commented

Im not a fan of the attributes tag in https://issues.apache.org/jira/browse/MNG-6288

It feels like dependencyManagement is the appropriate place for customizations, i.e. <dependencyManagement><exclusions>

Then could have like the OP suggested <dependencies><gav>

 

jira-importer avatar Nov 02 '20 22:11 jira-importer

Guillaume Nodet commented

FWIW https://github.com/maveniverse/mason Note that it should now be easy to add in mason a slightly different XML parser supporting the compact syntax.

jira-importer avatar Mar 29 '25 17:03 jira-importer

  • Out of curiosity, I want to know whether pom.yaml, pom.json, pom.conf, pom.hocon, pom.toml used by https://github.com/maveniverse/mason will replace pom.xml as the default in Maven 4 or Maven 5?

linghengqian avatar Jul 25 '25 01:07 linghengqian

  • Out of curiosity, I want to know whether pom.yaml, pom.json, pom.conf, pom.hocon, pom.toml used by https://github.com/maveniverse/mason will replace pom.xml as the default in Maven 4 or Maven 5?

I personally doubt that (and would vote against it, as XML is the only format you can validate with a schema)

Bukama avatar Jul 25 '25 05:07 Bukama