pantsbuild / intellij-pants-plugin

IntelliJ Plug-in for Pants Build
Apache License 2.0
74 stars 55 forks source link

pants intransitive dependencies #311

Open viktortnk opened 7 years ago

viktortnk commented 7 years ago
jar_library(
    name='finatra-jackson',
    jars=[
        scala_jar('com.twitter', 'finatra-jackson', '2.12.0', intransitive=True)
    ])

Even though I specify dependency as intransitive, plugin still brings all if it's modules in scope

screenshot 2017-08-22 16 48 04
baroquebobcat commented 7 years ago

Hm. This might be an issue on the pants side. Does running ./pants export on the target also collect all of these jars?

viktortnk commented 7 years ago

@baroquebobcat Nope, ./pants export only shows finatra-jackson, without it's dependencies

wisechengyi commented 7 years ago

@viktortnk I tried with your build file. It does seem to be intransitive. Do you think that it could be leaked from somewhere else, i.e. the extra jars belong to some other deps?

$ ./pants export 3rdparty/jvm/com/twitter:finatra-jackson
{
    "preferred_jvm_distributions": {
        "java7": {
            "non_strict": "/Library/Java/JavaVirtualMachines/TwitterJDK/Contents/Home"
        },
        "java6": {
            "non_strict": "/Library/Java/JavaVirtualMachines/TwitterJDK/Contents/Home"
        },
        "java8": {
            "strict": "/Library/Java/JavaVirtualMachines/TwitterJDK/Contents/Home",
            "non_strict": "/Library/Java/JavaVirtualMachines/TwitterJDK/Contents/Home"
        }
    },
    "libraries": {
        "com.twitter:finatra-jackson_2.11:2.12.0": {
            "default": "/Users/yic/.ivy2/pants/com.twitter/finatra-jackson_2.11/jars/finatra-jackson_2.11-2.12.0.jar"
        }
    },
    "version": "1.0.9",
    "targets": {
        "3rdparty/jvm/com/twitter:finatra-jackson": {
            "pants_target_type": "jar_library",
            "is_target_root": true,
            "globs": {
                "globs": []
            },
            "targets": [],
            "roots": [],
            "is_code_gen": false,
            "is_synthetic": false,
            "target_type": "SOURCE",
            "id": "3rdparty.jvm.com.twitter.finatra-jackson",
            "libraries": [
                "com.twitter:finatra-jackson_2.11:2.12.0"
            ],
            "scope": "default",
            "transitive": true
        }
    },
    "jvm_platforms": {
        "platforms": {
            "java7": {
                "source_level": "1.7",
                "args": [],
                "target_level": "1.7"
            },
            "java6": {
                "source_level": "1.6",
                "args": [],
                "target_level": "1.6"
            },
            "java8": {
                "source_level": "1.8",
                "args": [],
                "target_level": "1.8"
            }
        },
        "default_platform": "java8"
    }
}
viktortnk commented 7 years ago

@wisechengyi Other modules in project depend on finatra-http which has finatra-jackson as dependency. So you think it comes from there? I didn't expect it to work that way.

wisechengyi commented 7 years ago

You could do the same export command to check for that

viktortnk commented 7 years ago

Hm, I'll try to explain my case

Let's consider 3 pants modules: api - has case classes as REST api protocol definition + validation annotations from finatra core [depends on api] - implements business logic controller [depends on api and core] - finatra http layer

I want keep api module very light on dependencies, but use annotations coming from finatra-jackson

So I define separate target for it in Pants: jar_library( name='finatra-jackson', jars=[ scala_jar('com.twitter', 'finatra-jackson', '2.12.0', intransitive=True) ])

and make build of api module have just this piece:

scala_library( dependencies=[ '3rdparty:finatra-jackson', ] )

obviously I use finatra-http target on a controller module, as it works with http layer, but it is not in any dependencies of api and core

So it looks like Pants bringing all dependecies of finatra-jackson in scope for compilation, although it is defined as intransitive:

So in api module I'm allowed to do this:

import com.twitter.finagle.Http
import com.twitter.finatra.validation._

case class OAuthPayloadData(@NotEmpty code: String, @NotEmpty redirectUri: String)

object A {

  val c = Http.client.newService("google.com")
}

(validation package is part of finatra-jackson, but finagle.Http is definitely not)

For above code snipped, neither IDEA, nor Pants compilation complaining (tried also rebuild after ./pants clean-all). Is it expected behaviour?