i specify my dependencies like the following:
dependencies {
compile files(
'v:\company\components\component1\v1\00\01\release\myComponent1.jar'
,'v:\company\components\component2\v1\00\01\release\myComponent2.jar'
,'v:\company\components\component3\v1\00\01\release\myComponent3.jar'
,'v:\company\components\component4\v1\00\01\release\myComponent4.jar'
,'v:\company\components\component5\v1\00\01\release\myComponent5.jar')
}
now in each of thse component versions, if you are in a release, you go up one directory and go into src you find jar with the sources in.
v:\company\components\component1\v1\00\01\src\myComponent1.jar
Is there anyway i can also reference those from my gradle build script for both intellij idea and eclipse?
Thanks.
Related
What is the exact dependency I need to develop a Gradle Plugin in Java? Ideally I would like to get it from a well-known repository such as Maven Central or similar.
I have a Maven project with a core functionality and I just added two extra plugins, one for Ant, one for Maven. They are already tested and working; easy! Now, I wanted to add a third module for a Gradle plugin to make this functionality also available from any Gradle project.
However, I can't find the exact dependencies I need to develop a Gradle plugin.
The Gradle docs (such as https://docs.gradle.org/current/userguide/java_gradle_plugin.html) are not very well written to say the least. They mention:
the gradleAPI() dependency
or the java-gradle-plugin dependency
But they are quite unclear... no group, no version (really?).
If anyone can enlighten me to where I can get these dependencies from, I would be very thankful.
Gradle's public and internal APIs, aka gradleApi(), are bundled with the Gradle distribution and not independently published and therefore not easily consumable by Maven builds. There's the pending epic #1156 (Ensure plugin cross-version compatibility by allowing a user to depend on gradlePublicApi()) that might help here.
Since Gradle plugins are best to be built with Gradle, a pragmatic solution is to invoke the Gradle build from Maven and attach the produced artifact to the Maven build. Andres Almiray (aalmiray) once described this in the blog post Running Gradle Inside Maven (Web Archive Link). He describes the following high level steps:
Create a new Maven module (e.g. gradle-plugin) and add attach it to the parent POM
In the POM of gradle-plugin add a dependency to your core module. Use the maven-dependency-plugin to store dependencies to the Maven build folder, e.g. target/dependencies.
Create the build.gradle, add a Maven repository that points to target/dependencies (step 2) and let it depend on the core module as well as gradleApi(). Implement the Gradle plugin.
Use the exec-maven-plugin to invoke the Gradle build.
Use the maven-resources-plugin to copy the Gradle built plugin jars to the standard Maven build folder.
Use the build-helper-maven-plugin to attach the copied jars to the Maven build.
Sample project to be found here (gradle-in-maven).
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project
In here it is mentioned that it is gradleApi() and I know that this works (from experience). The localGroovy() on that page is only needed if your plugin code uses groovy (does not apply if you only use groovy in the build.gradle of your plugin).
java-gradle-plugin is a library that makes it a bit simpler to make plugins, it is not required though. I personally prefer using gradleApi only.
EDIT:
It appears I've misunderstood the question. Here are the steps to get gradleApi jar:
Create a Gradle project with your desired Gradle version.
Add implementation gradleApi() dependency.
Import/run the project once.
Go to your .gradle folder (located in home folder in Linux-based operating systems).
Open caches folder
Open the version folder you want, e.g. 6.0.1
Open generated-gradle-jars folder.
Copy the jar to wherever you want and use it.
For me the 6.0.1 jar is at ~/.gradle/caches/6.0.1/generated-gradle-jars/gradle-api-6.0.1.jar
Please note that I have not tested this, I know the jar is there but I haven't tried using it.
Does gradle work like go mod ? First importing some dependencies in java file such as import org.apache.hadoop.mapreduce.Mapper, then calling gradle build and gradle would generate dependencies in build.gradle automatically, also download all the jars needed to gradle cache.
Or, all the denpendencies we need must add to build.gradle manully? Which version should append to the denpendency, search in the maven repo one by one?
Thank~
Gradle uses the dependencies declared in the build file to create the compile classpath. Similarly it will use test dependencies for the test compile classpath and the test runtime classpath.
So you have to declare the dependencies first, including figuring out which version you want to use in your project, and then you will be able to compile and run code that leverages these libraries.
I have a simple testing-purpose gradle project, which I want to scan its dependencies using gradle dependencies command. Before I do so I want to make sure that the project's dependencies are actually found in the gradle's cache (.gradle/caches/modules-2/files-2/1). To do so I run the gradle assemble command to download the missing dependencies before scanning.
I found out that its working only if the project has a src/main/java folder with a Java file inside it (even if that Java file is completely empty).
Is this a valid workaround? Is there any better solution to guarantee the dependencies are found in the cache folder before scanning them?
What is the reason that you want to do that?
assemble task assemble your source files, if there is nothing to assemble the task is not needed to run. The fact you are adding the java file to src its a hack to run this task and its children tasks.
Depending on what you want to achieve there are few ways to 'scan' dependencies.
For more info you can visit https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies
Aditionally:
There is a netflix plugin that I believe can scan through your gradle scripts a check unused dependencies https://github.com/nebula-plugins/gradle-lint-plugin
There is a plugin that can scan the vulnerabilities of used dependencies etc https://jeremylong.github.io/DependencyCheck/dependency-check-gradle/
When creating an artifact in IntelliJ IDEA and adding dependencies to my pom.xml, the artifact dependencies are not updated. If I then export the JAR file using my artifact configuration assuming everything is fine, I will get a class not found exception since the dependencies were not fully exported.
Is there a way to make IntelliJ automatically use all dependencies for exporting? I understand that this is not always desired behavior when using multiple artifacts (to cut down on the file size) but mostly when only using one artifact it is preferred to not having to delete and recreate the artifact configuration frequently.
This looks like a job for Shade plugin
Just import jar manually to project library
Project>Open Module Setting >Libraries>"+" sign in middle tab ( add new project library - from Maven) > type Your file and add it
I have the following dependency in my gradle file.
compile 'org.A:A:1.0'
which automatically pulls in
'org.B:B:1.0'
and many other jars which it depends on.
But,my project requires repackaged A.jar (let's call it A*.jar which I installed in a local maven repository as custom version).
So now I change the dependency as below
compile 'org.A:A:custom'
which doesn't pull in any of the dependencies mentioned in the pom.xml file present inside the A.
jar file (which it would, had it been org.A:A:1.0)
My questions are:
1) Based on what does the statement compile org.A:A:1.0 pull other jars ? Is it pom.xml file present inside the jar?
2) What are the changes required if I want to automatically pull in both 'org.B:B:custom' and regular versions of other jars which are dependee of org.A:A:1.0
Maven will read the pom file for the artifact it resolves as well. In there the dependencies are found and resolved.
You simply need to also upload the pom of A*.jar and modify the version of it accordingly to A* - that should already do the trick.