How to add external jar files in gradle project inside the netbeans - netbeans

I have created the Gradle web app which is running inside the NetBeans. Now I want to add some external jar files in it so how can I add the jar from NetBeans.

Modify your Gradle project to add your dependency and refresh it in NetBeans to pick up the changes. There is plenty of documentation how to do it. For example How to add local .jar file dependency to build.gradle file?

If you really need to take that .jar from a local directory,
Add next to your module gradle (Not the app gradle file):
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'gson-2.2.4'
}
ref:check here

Related

Gradle other project as dependency in eclipse

I have a web application which depends on another standalone project. Simply the web project requires a standalone project jar to be in classpath. I have built the standalone project jar with gradle and included that in web application's WEB-INF/lib folder. The project is running as expected. Now i want to make it automatic by adding that project as dependency. This is also achieved using the following code.
settings.gralde
include 'job-invoker'
project(':job-invoker').projectDir = new File(settingsDir, '../job-invoker')
build.gradle
dependencies {
compile project(':job-invoker')
.
.
}
I'm able to build the war file from command line using gradle and run it in tomcat. But i'm getting errors in eclipse. I'm not able to run the project in eclipse due to the compilation errors. Can some one please help me. Thanks in advance.
Finally i found a solution for this by installing the other project in maven local repository and adding this as a regular dependency in project. Reference code is given below.
Other project Gradle file
apply plugin: 'maven'
group = 'com.xxx.job'
version = '1.0'
Run gradle install command on this project. Then add mavenLocal() to your repositories in another project and add the dependency
compile 'com.xxx.job:job-invoker:1.0'

How can the source attachment, Javadoc location and native library location be specified for a Gradle project's local dependency, in Eclipse?

The Eclipse IDE for Java Developers (Neon) as well as the default Gradle plugin (Buildship?) are used.
A Gradle Git project was created using the Eclipse IDE. A local JAR is stored within the workspace/ProjectName/lib/nameOfJAR.jar directory. It was added to this project as a dependency, using the following build.gradle configuration.
...
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
flatDir {
dirs 'lib/'
}
}
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
compile name: 'nameOfJAR'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
Then Project Explorer > Project A > Gradle > Refresh Gradle Project was used to update the Eclipse GUI, to display this new local dependency, via Project Explorer > Project A > Build Path > Configure Build Path > Libraries > Project and External Dependencies > [Name of JAR].
However, when expanding this section, source attachment, Javadoc location and native library location are shown as non modifiable. Can these be set from the Gradle configuration files?
How can these be set through Eclipse and Gradle?
You can place nameOfJar-sources.jar file next to the actual library in the same directory. Gradle will use that as a source attachment. I suppose the same would work for javadocs, that is nameOfJar-javadoc.jar would be picked up. I don't know how native libs are handled.
This is probably described somewhere in the Gradle docs, but I don't know where to find them.

Gradle: produced WAR file has two versions of JAR from child project

I have a root project that builds WAR, and two child projects that build JARs. The root project references the child project in this way:
apply plugin: 'war'
jar.enabled = false
war {
dependencies {
runtime project(':application1')
runtime project(':application2')
}
}
application2 depends on application1:
dependencies {
compile '...:application1:1.+'
}
The WAR file includes two versions of application1.jar: one from repository, another just built.
EDIT: Application2 has to depend on application1 as a JAR because that simplifies debugging in Eclipse with embedded Jetty: Eclipse automatically adds application1.jar to classpath of Jetty server launch configuration.
You have specified dependency on application1 project differently for the root project and for the application2.
For your application2 it was made as dependency on a library within some repository, but your root project depends on it as on a subproject. Gradle can't determine, that some library in the repo is the same, as subproject's artifact.
If you don't want to get 2 versions of the same lib, you have to make it dependent from the same library: either as
compile '...:application1:1.+'
or as
runtime project(':application1')
Anyway, it seems to be prefferable, to make it depending on the same subproject in both cases, rather then on some project and on the library in repo.

Developing exploded war in Eclipse

I have a project with standard maven layout:
src/main/java
src/main/webapp
I want to develop this project in Eclipse in such a way, that Eclipse would compile my classes into exploded war folder, smth like this:
build/webapp/WEB-INF/classes
And I do not use maven as a build tool, I use gradle. Is it a way to configure Eclipse, that my output folder of the project is of correct structure for exploded war?
task explodedWar(type: Copy) {
into "$buildDir/exploded"
with war
}
war.dependsOn explodedWar
With these lines of code in your web module build.gradle you can have your generated war exploded
You can change this by adding the following to your build.gradle file:
apply plugin: "eclipse"
eclipse {
classpath {
defaultOutputDir = file("${buildDir}/webapp/WEB-INF/classes")
}
}
This sets the output dir to the correct directory. Also take a look at the Gradle DSL reference

How to have maven build my project with all the dependencies in a separte folder, ready to package?

How do I create a package of a Maven project that contains the jar with my classes, plus a directory like "lib" with all the needed dependencies? I'm using netbeans ...
You can copy required libs into a folder using Maven dependency plugin copy-dependencies goal.
In addition to that you can use Maven assembly plugin to create an archive containing your jar and this lib folder.