Why does apt think it needs this extra dependency?

I'm working on some machine setup instructions, and I was surprised to find out that apt-get install A B can behave differently than apt-get install A && apt-get install B.

My specific example is A == openjdk-7-jdk and B == ant.

So, openjdk-7-jdk depends on openjdk-7-jre-headless, which satisfies ant's dependency java6-runtime-headless. But if you install them as apt-get install openjdk-7-jdk ant, APT doesn't seem to figure this out and installs default-jre-headless. But if you install openjdk-7-jdk prior to installing ant, its dependency is satisfied and all is good.

APT is usually smart enough to figure this sort of thing out, so why can't it do so in this case? I'd like to have a better understanding as to why it works this way, so this sort of thing doesn't trip me up again in the future.


Seems that there is some kind of "weight" system playing here:

$ aptitude why ant openjdk-7-jdk
p   ant                 Recommends ant-optional       
p   ant-optional        Suggests   libgnumail-java    
p   libgnumail-java     Suggests   libgnumail-java-doc
p   libgnumail-java-doc Recommends default-jdk-doc    
p   default-jdk-doc     Depends    openjdk-7-doc      
p   openjdk-7-doc       Suggests   openjdk-7-jdk

As you can see ant depends of openjdk-7-jdk due a complicated and intricated amounts of suggestions, recommendations and dependency, while when using openjdk-6-jdk the dependency is more direct:

$ aptitude why ant openjdk-6-jdk
p   ant           Suggests default-jdk | java-compiler | java-sdk
p   openjdk-6-jdk Provides java-sdk

Of course aptitude methods of dependency resolution, could be different of apt-get's. BTW, running a simulation of ant without openjdk-7-jdk installed don't pulled openjdk-6-jdk:

$ sudo apt-get install ant
[sudo] password for braiam: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  ant-optional
Suggested packages:
  default-jdk java-compiler java-sdk ant-gcj ant-doc liboro-java junit
  libregexp-java jython antlr libbcel-java libjdepend-java libgnumail-java
  libcommons-net-java libjsch-java javacc ant-optional-gcj
The following NEW packages will be installed:
  ant ant-optional
0 upgraded, 2 newly installed, 0 to remove and 9 not upgraded.
Need to get 2,234 kB of archives.
After this operation, 3,041 kB of additional disk space will be used.
Do you want to continue [Y/n]? 

Maybe if you use the same methods as I did, you could figure out more, since I'm using Debian testing right now and repositories could have changed in the meanwhile.