Configuring Gradle project to depend on lwjgl - java

How do I configure build.gradle to depend on LWJGL?
I'm new to Gradle, and how to configure library dependencies is clear as mud to me.
It's my understanding is that one can specify library dependencies for Gradle to download rather than checking them in to source control, but any sort of help with configuring things would be appreciated.
(I don't know any Ivy or Maven.)

I think what you want is to have lwjgl in your build classpath and resolve it automatically right?
try this snippet:
plugins {
id "java"
}
repositories{
maven {
url = "http://adterrasperaspera.com/lwjgl"
}
}
dependencies{
implementation "org.lwjgl:lwjgl:2.6"
implementation "org.lwjgl:lwjgl-util:2.6"
}
This snippet above defines a maven repository which contains the lwjgl libs and defines two compile dependencies to your project.
regards,
René

Related

How to import 3rd party library using mavin into Java project using gradle?

I want to use the sxcml-java library in my son's school's robotics code (currently a private repo).
The library uses Maven. I was able to successfully include the library in a test project using Maven.
However, I've just discovered that the existing robotics project code uses Gradle. I don't know either Maven or Gradle, and I haven't programmed in Java in almost 30 years.
How can I most easily use scxml-java - which itself has external 3rd party dependencies — in the robotics project?
This question is similar to this one, but the solution there was easy because both projects were using Gradle.
Provided the package is published in an artifactory, which is the case (See here), you can just include it as any other Gradle dependency (using groupId, artifactId and version), regardless of what build system was used to build it in the first place.
dependencies {
implementation 'com.nosolojava.fsm:scxml-java-implementation:1.0.1'
}
If you use IntelliJ IDEA, pasting the Maven dependency block into the build.gradle file will automatically convert it into the Gradle dependency format like the one above.
Please note however this does not apply to plugins, only to regular dependencies.
If You install your jar or third party jar into maven local repo like ~/.m2
you can add mavenLocal()
repositories {
mavenCentral()
// * Require by Use JAR install to Maven Local Repo your .m2
mavenLocal()
}
then add implementation to dependencies
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
implementation 'yourGroupId:yourArtifactId:yourVersion'
}
Please mapping yourGroupId , yourArtifactId, yourVersion from your pom.xml
If You only download third party jar into foler like /home/yourName/your-libs
you can add configurations
configurations {
sxcml-java-lib
}
then add dependencies
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
//sxcml-java-lib fileTree(dir: "${System.getProperty("user.home")}/libs", include: "*.jar")
sxcml-java-lib fileTree(dir: "/home/yourName/your-libs", include: "*.jar")
}

How do I add libraries to my Gradle file?

It's probably very simple, but only to people who know what they are doing.
I have a Java program that imports these two:
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
As an aside, I don't want to use the lang3 package but the lang package.
I do not have anything in my Gradle file about these. When I try to build the file, it gives me errors for these two, saying the packages do not exist.
My questions are:
Do I need to add them as "compile" or as "api"?
What is the exact syntax? I have lines that look like this:
api group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
How do I find the right name (or should I just invent one)? and the version?
Anything your code needs (besides basic JRE classes) is a dependency for your code. Gradle manages these dependencies, usually downloading them from a repository.
First you need to find such a repository. You probably have repositories already configured in your build.gradle, like so:
buildscript {
repositories {
mavenCentral()
// maybe more repositories
}
}
That means Gradle will try to download dependencies from Maven Central. You can either do a web search for "gradle" and your dependency, or go to repository and search, or check the dependency's homepage.
You'll end up with a dependency name and version like 'org.apache.commons:commons-lang3:3.12.0'. This needs to go in your build.gradle.
Gradle has different dependencies:
buildscript dependencies provide code that Gradle needs to execute to build your project, e.g., a tool to pull in version control system information or generate code
implementation dependencies are dependencies your code needs to run, like a logging framework or JSON parser or PDF generator
test dependencies are dependencies needed to run your automated tests, like JUnit
Depending on where you need the dependency, you put it in the buildscript or the dependencies block.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.tmatesoft.svnkit:svnkit:1.9.+'
}
}
dependencies {
implementation 'pdfbox:pdfbox:0.7.3'
testImplementation 'junit:junit:4.+'
}
You don't need to repeat the implementation dependencies for the testImplementation btw, as it inherits them automatically.
You can define your own configurations as need; see the Gradle manual on dependencies, for example if you have different test suites (unit, integration, performance, ...) that need different dependencies.
you'll have to go to their official website and get the implementations then add those to the dependencies(you'll find it at the bottom of the file) in the build.gradle(module) it would look something like -
the $lifecycle_version might be somethiing like 1.2.3 or some version number.
this is what I got (not exactly sure if this is right)-
implementation 'org.apache.commons:commons-lang3:3.12.0'
got from library website in the gradle short tab
in the build.gradle(project), look for maven repo.
Once done, you'll be able to import the respective libraries.

How to attach gradle-api sources in IntelliJ

I'm working on a custom Gradle plugin. For some reason IntelliJ is unable to find the sources of the gradle-api artifact and only shows the decompiled .class file. I am already using the -all distribution of the Gradle Wrapper (which includes some sources, but apparently not the ones I need right here). Clicking Download... results in an error:
Sources not found: Sources for 'gradle-api-6.5.1.jar' not found
How do I correctly attach/choose sources for gradle-api in IntelliJ?
EDIT:
I have a minimal Gradle plugin with code like that (taken from the official samples):
plugins {
id 'java-gradle-plugin'
}
repositories {
jcenter()
}
dependencies {
testImplementation 'junit:junit:4.13'
}
gradlePlugin {
// ...
}
According to this excellent manual you should add gradleApi() as a runtimeOnly dependency:
dependencies {
//...
runtimeOnly(gradleApi())
I guess that, the default Intellij config use gradle from gradle-wrapper.properties file will use /gradle/wrapper/gradle-wrapper.jar, but it doesn't contain source code. what you need is a jar like gradle-wrapper-all.jar. But I don't know how to let Gradle redownload that. Just setting Wrapper.DistributionType.ALL is not working.
Solution
set Wrapper.DistributionType.ALL
wrapper {
jarFile = file(System.getProperty("user.dir") + '/gradle/wrapper/gradle-wrapper.jar')
gradleVersion = '6.7.1'
distributionType = Wrapper.DistributionType.ALL
}
I download Gradle, and use it. Set two things here and refresh it.
Here is the source code, the version is right and with all in the name (gradle-6.7.1-all):
delete gradle dir
run "gradle wrapper"
check the suffix "-all" in the file gradle/wrapper/gradle-wrapper.properties
sample:
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

How to prepare a plugin dependency tree in Gradle 5.x? [duplicate]

One can run gradlew dependencies to learn about dependencies of module tasks. It there a way to find transitive dependencies of buildscript dependencies?
Example:
classpath 'com.android.tools.build:gradle:1.0.0' depends directly on:
com.android.tools.build builder
com.android.tools.lint lint
net.sf.proguard proguard-gradle
tools.base project-test-lib
As can be seen on MVNRepository. But this artifacts have their own dependencies. Is there and way to find those out without manually traversing whole dependency tree?
As a clarification, the classpath I'm talking about is defined by:
buildscript {
repositories {}
dependencies { .... }
}
Beginning with Gradle 2.10 you can now get information on buildscript dependencies via
gradle buildEnvironment
With older versions you'll have to explicitly define a task of type DependencyReportTask configured with your build script configuration.
task buildscriptDependencies(type: DependencyReportTask) {
configurations = [buildscript.configurations.classpath]
}
I think you're looking for Gradle's DependencyInsightReportTask
You can use this command:
gradle dependencyInsight --dependency gradle
There is awesome tutorial by Udacity, Gradle for Android, but you can watch this video for more explanation.

Android Studio doesn't find com.android.support:support-v4:19.1.0

I have imported one project into Android Studio but I got the error:
Could not find com.android.support:support-v4:19.1.0.
Where could I find this file? I have imported the project using Gradle.
I have the Android Studio version 0.5.7 the last android sdk and java 1.7u55.
Just add this code to you build.gradle file
dependencies {
compile 'com.android.support:support-v4:19.+'
}
and press Tools -> Android -> Sync Project with Gradle Files
Gradle will download necessary files by himself
It does not work for me either. It works with 19.0.1
But if (I use gradle) I do this in my build.gradle:
repositories {
def androidHome = System.getenv("ANDROID_HOME")
mavenCentral()
maven {
url "$androidHome/extras/android/m2repository/"
}
}
It finds the artifact.
From the SDK Manager, delete and re-install the Android Support Library 19.1 package.
I had this same problem with morning. I found the Jar file that I needed in /<MySdkFolder>/extras/android/support/ - in there are some sub folders with the different support libraries in them, so the last part of the path depends on which one that you want to use.
I just copied this into the lib folder of the project. I'm sure there is a more technical solution but it worked for me.
Following theory works at me:
Android Studio has problems importing support-v4:19.1.+ library when it comes through a transitive dependency.
Solution Adding support-v4 as own dependency and exclude this lib where it comes transitive. then i could not more see this import issue
Right clicking on the library and select the import as library option from the context menu works for me.
Try to go
Project Structure -> Dependencies -> Add : then select -> File
dependecies
then select the proper library
This artifact is available on google maven repository. So need to add following in the build.gradle:
allprojects {
repositories {
mavenLocal()
google()
}
}
I had a similar problem. This line to build.gradle works -->
implementation 'com.android.support:support v4:28.0.0'

Categories

Resources