0

i have a maven multi-module project:

  • root
    • commons
      • common-module
    • plugins
      • plugin

commons and plugins don't have the same parent, and are "standalone".

in commons-module i define 2 profiles, projectA and projectB. in each of these profiles i define properties, such as dep.version, dep1.version etc... later i use these properties in dependencyManagemnt for the version part in the dependencies of "dep" and "dep1" section.

in plugins (who is parent for plugin) i have a dependency scope import on commons-module to obtain the list of dependencies. when i build the plugin module, it doesn't seem to matter if i do -PprojectA or -PprojectB: maven says they don't exist. they do exist, but in commons module, which i import. so the dependencies i get don't have the correct versions when i mvn dependency:tree

is what i'm trying to achieve possible, am i don't something wrong, is this a maven bug, or a none-supported feature? anyone got a clue?

thanks, Nathan.

nathan g
  • 858
  • 9
  • 17
  • What do you mean by "import"? Do you simply declare a dependency on that artifact? – Sergiu Dumitriu Dec 23 '12 at 15:23
  • no, i declare a dependency on the pom file with scope "import". please see [import scope](http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies) – nathan g Dec 23 '12 at 20:09
  • If they don't have the same parent, why did you put them both under `root`? – Daniel Kaplan Dec 24 '12 at 20:23
  • 1
    @DanielKaplan See [this post](http://stackoverflow.com/questions/1992213/maven-parent-pom-vs-modules-pom) for more details regarding pom inheritance vs module containment. – Jeff Putney Jan 22 '13 at 15:20

3 Answers3

2

Import scope only imports the dependencyManagement, not the dependencies themselves. You still need to declare the dependency on the artifact, and then the version, and scope etc will be picked up from the dependencyManagement.

I don't think import will work for pluginManagment sections. The documentation you linked to only mentions dependencyManagement, and the only other mention I've seen is this unanswered question to the mailing list.

Jeff Putney
  • 403
  • 3
  • 8
1

Dependencies aren't allowed to change the POM of modules that simply use those dependencies. It wouldn't be a safe thing to do. Imagine that you're adding another dependency to your project, and suddenly the build stops working because the dependency actually overrides some of your settings.

POM interpolation inherits settings only from ancestor projects, going up the <parent> chain.

Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
  • this is not true. please see [import scope](http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies) – nathan g Dec 23 '12 at 20:09
0

You are trying to use the import scope with profiles. However, profiles are not activated transitively, so the different dependencies in your import-scoped dependency's POM aren't being activated.

It's probably not recommended, but you could have two different commons modules, and include the import-scoped dependency in profiles that refer to one or the other in your current project.

Christopher
  • 2,427
  • 19
  • 24