I'd like to know where dependency jars are downloaded. Originally, I wanted to know this since I was trying to understand how I could add these jars specifically to my project class-path in my IntelliJ project but found a workaround here. But I'd just like to know what gets downloaded to what location on my machine.
Thanks
Gradle's dependency cache is located under ~/.gradle/caches. (Inspecting the dependencies of the generated IntelliJ project will reveal that.) The exact cache layout is unspecified, and may change between Gradle versions.
Related
I have an OSGI project, one of the dependencies is a jar with a wrong manifest value (wrong Bundle-NativeCode), so I get a null pointer exception when trying to install the plugin I build. Is there a way for me to modify the manifest of that dependency with the maven-bundle-plugin somehow?
I know the problem is the manifest because I modified the jar on my local .m2 repository, fixed the manifest and it works fine, but that is not reproducible and should be fixed at build time.
In my opinion it will be better to change this library to another, that don't have this bug or contact with company/developer and raise a bug.
But if you really need to use it, the only idea that comes to your mind is to create 2 projects. One it will be own maven plugin to unpack, fix and pack this dependency. And next one that will have only the broken dependency and as result will have fixed package.
In your project insted of orginal libraty, you need to add fixed package.
I added com.googlecode.libphonenumber to my POM file. I expected to be able to add it as required to the module-info file, but I couldn't. I can see in the .m2 directory. I can see it in the IntelliJ project .iml file.
I can see in the external dependency list along with all the other dependencies. Nothing seems wrong, yet I am not able to use the library in the project and IntelliJ suggests I import maven dependency (nothing happens, that was step 1). I tried to invalidate cache and restart. I tried deleting .idea and .iml file and re-importing the project. This is one of those times when I have nowhere to go but here. It just doesn't make sense.
requires libphonenumber; in module-info did the trick. IntelliJ was not suggesting this, I had to do it manually. Nor did it recommend it in a drop down list of possible dependencies. Java modules still need some refining.
I'm working on another issue with getting my build.gradle to understand a workspace project dependency in my Android project. I've been using Java and Android for a while and I'm still easily confused about all the different ways to add a dependency. One way is to put a .jar file in the libs/ folder. Another way is to have a workspace project dependency. Another way (if working with Android) is to add a project dependency in the Android options menu? I feel like if I truly understood why there are these different dependencies and how they work maybe I wouldn't constantly have issues with managing my dependencies (even with Gradle). Why would one want a project dependency instead of a normal .jar in the libs/ folder? I'm not even sure how a project dependency itself works. By project dependency, I mean something like the Google Play Services project that I have to import into my Eclipse workspace. When importing into Eclipse it doesn't copy the actual directory into the workspace but it's more like a link to the directory. I know this is a big topic, maybe someone can show me a concise place to gain information.
Speaking in general terms, if you add a jar to lib folder, it will (usually) be packed along with the rest of your code. Project dependency adds a compile-time dependency, but (as you already said) it will not be packed into your build. However, that dependency will have to be satisfied at runtime (meaning, for example, Google Play Services will have to exist on the device that runs your code). Aside from that, gradle keeps "its own set of dependencies" to be able to build the application not depending on the IDE you are using. But most IDEs are well integrated with build tools, so they automatically synchronize dependencies between IDE project dependencies, and build tool's dependencies. I hope this makes sense :)
A bit of background about my knowledge level: I'm currently trying to learn how to build a project with gradle. So far I don't have much experience with build tools (almost none). I do understand the general idea and have seen ant and maven files before but never written them myself. Until now I just used other peoples build scripts or configured my builds using Eclipse. So I might be on a completely wrong track here, if so please point me in the correct direction.
Also, I sadly don't have much experience building jars by hand.
I have an Eclipse project which I want to compile into a jar. Required library jars are on my local file system. I managed to make gradle use these via
dependencies {
compile fileTree(dir:'lib', include:'*.jar')
}
in addition I have my source files in src/main/java and just use apply plugin: 'java' in the build.gradle file. Trying to build the project with gradle build seems to do the right thing, as far as I can tell.
However, the library is supposed to be used in a web project running on a tomcat and makes use of some libraries that are supplied by tomcat, as far as I understand. E.g. I'm using javax.servlet.http.HttpServletRequest.
The project works fine in Eclipse, but there I have the tomcat library added to my Eclipse build path. When I check in Eclipse I can see that javax.servlet.http.HttpServletRequest is part of the servlet-api.jar which is part of the Tomcat library.
Now, when I build the project I get build errors because the java compiler cannot find the class because I didn't specify the servlet-api.jar in the dependencies. I guess I could download it somehow (or learn how to specify it as an external dependency to make gradle download it from some repository) but I am not sure whether that would be correct.
Is there a way to tell gradle to use the same library that Eclipse uses? Or some other general way to tell it about all the tomcat jars, the same way I can simply add the complete Tomcat library in Eclipse?
Or do I actually need another copy of these jars somehow and have to specify each one individually?
Also, do I need to add these library jars to my build-result library jar? As far as I know I need to add any jar I depend on to the resulting jar as well. But then again, I have read somewhere that some libraries are supplied by tomcat itself so they would have to be part of any war deployed on it.
I'm afraid, I'm confused by the combination of how to build a jar-file to be used in a war-file to be deployed on a tomcat using gradle and I don't know from which of these parts my problems originate. I hope someone reading this can help me untangle my thoughts and point me in the right direction or at least tell me how to add the jars included in the Tomcat library to my gradle dependencies.
With Gradle, whenever you add files or directories as dependencies, they are not treated as full-fledged artifacts (with group, name and version), but rather as simple files containing classes. It means that Gradle will not perform any conflicts resolutions on them, or pull transitive dependencies.
For you, just to get started, I recommend just to add tomcat dependency. Make sure it is the same version as the one in Eclipse.
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'org.apache.tomcat:tomcat-catalina:7.0.47'
}
Also, look into Eclipse Integration Gradle project as a long-term solution.
So every time I add a dependency to a library using maven in my pom.xml, it doesn't get deployed until I go to module settings and then click on 'fix'.
This happened when I added freemarker.
Why doesn't IDEA do this for me? Am I missing a step?
Not sure about previous versions but with IntelliJ 9, IntelliJ shows me a Import Changes link when I modify a pom.xml and also offers to Enable Auto-Import:
alt text http://www.imagebanana.com/img/emcut3ku/screenshot_008.png
The auto-import option is also available from the Maven Integration dialog: File > Settings > Maven > Importing > Import Maven projects automatically.
IDEA stores all of your module's dependencies in either a .iml or .classpath file (based on your preference).
When you change the pom.xml file, it needs to resolve the new set of dependencies (Re-import) and update the file accordingly. I can only imagine that they don't do this automatically for you because they can never really know when you are done working with the file, and causing resolution of dependencies to start while you're still typing would make working with pom.xml from within idea very irritating.
AFAIK, you're doing it right. In my version of IDEA, I see a "re-import" button that appears in the pom file editor (which saves a couple of clicks)... or you can go to the "Maven Projects" window and click the "Re-Import Maven Projects" button, but these should do the same thing as your "Fix" button in the project settings.
The original question referred to a library that wasn't deployed -
IntelliJ uses artifacts to deploy build output and required libraries to application/web servers, and currently those can include a constant list of dependencies. Clicking the "fix" simply adds module dependencies to the artifact, if they weren't already there.
Since in most use-cases this is 1:1, i.e. artifacts contain all module dependencies, I have opened an feature issue for it:
http://youtrack.jetbrains.com/issue/IDEA-99458