Gradle subproject jar and add to Eclipse referenced libraries - java

I have a repo at http://www.github.com/kourbou/HyperQuest.
I have a git submodule to a project called SpongeAPI. I would like to add the compiled jar of the subproject to the Eclipse project automatically but I have failed at doing so. I have added this to my gradle.build :
dependencies
{
jar project('SpongeAPI')
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
But the build fails and this happens:
A problem occurred evaluating root project 'HyperQuest'.
> Could not find method jar() for arguments [project ':SpongeAPI'] on root project 'HyperQuest'.
Could someone give me an example or write a gist of a build.gradle that works? Thanks.

Either set up multi-project build or publish the output of SpongeAPI into some repository and consume it from that place.
Multi-project build is described in http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html#sec:examples - you will add settings.gradle that will include SpongeAPI and then the dependency is like compile project(':SpongeAPI').
The publish approach means that you will upload the artifact from SpongeAPI build into a repository and your build will add this repository (like you add mavenCentral() or jcenter()) and refer to your artifact using common notation. Again there is a documentation to help you with that - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10669

I know you posted this early on in SpongeAPI's development, but I'll add this here for future readers.
By including SpongeAPI as a git-submodule, you are potentially tying your plugin to a specific, in development version of the API.
Instead, we provide a maven repository that you should use at https://repo.spongepowered.org/maven/
When using a version of SpongeAPI you MUST stick to released API versions, and not snapshots.
Otherwise your plugin has the potential to break on dev releases of the API.
You can read up to date information on how to set up a Sponge Plugin project here: https://docs.spongepowered.org/stable/en/plugin/project/index.html

Related

Build failed : Cannot find JAR 'aws-java-sdk-core-1.11.948.jar' SpringBoot

I'm trying to run spring boot project, but i get this error.
any idea what error is this ?
Cannot find JAR 'aws-java-sdk-core-1.11.948.jar' required by module 'gradle-resources-s3' using classpath or distribution directory '/home/mbunderline76/.gradle/wrapper/dists/gradle-7.3.2-bin/4k4cn06q0rruwh9dpndf9gmi8/gradle-7.3.2'
You need to add dependency for the jar required by your gradle version. Trying adding this dependency and refreshing your gradle.
implementation group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.948'
or
implementation 'com.amazonaws:aws-java-sdk-core:1.11.948'
Running on M1 Mac with Kotlin, Adding
configurations.all {
resolutionStrategy {
force ("software.amazon.awssdk.crt:aws-crt:0.16.12")
}
}
to the build.gradle.kts file (don't forget to refresh) worked for me as a work around per this(https://github.com/awslabs/aws-sdk-kotlin/issues/473) github issue

JitPack.io does not pull up the library! Why?

I have an old 12 year old project that I want to redo. I added Gradle to the project. Now I need to add a library from GitHub to the project (using Gradle), and I saw such a thing as JitPack. I configured and ran everything, but the library still doesn't pull up. What is the problem?
Gradle:
plugins {
id 'java'
}
group 'org.opensourcephysics.cabrillo'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.OpenSourcePhysics:osp:master-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Library from GitHub:
All my libraries:
What JitPack does is build your project and leverage the artifact on the fly when gradle asks for it. But for this to happen JitPack need to build the project in the repository you're asking for.
JitPack supports project such as gradle project, maven projects etc... check this link for a more detailed list of supported projects.
The repository you're trying to use OpenSourcePhysics/osp doesn't have a build script or anything like that, which makes it impossible for JitPack to build it and provide the artifact resulting for the build.

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver despite the fact it is in dependencies of gradle.build file

I have read top 10-15 questions with answers by the following query https://stackoverflow.com/search?q=com.microsoft.sqlserver.jdbc.SQLServerDriver%22
However, I still don't understand why it doesn't work.
Usual steps to solve this issue:
Make sure that the jar is add to as a dependecy in your build/dependency management tool (Ant/Maven (pom.xml)/Gradle(gralde.build))
Yes, it is in my case:
dependencies {
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.4.0.jre8'
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.4.0.jre8'
}
in build.gradle file
and gradle build command works without exceptions.
An alternative solution is to download jar file manually from https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15
and then add it to a classpath. This solution is undesirable i don't want to do something manually that has to be done by a build tool.
So the question is why I am getting the error "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" and I cannot see this jar in the dependencies tab
despite the fact that the jar is mentioned in my build.gradle file in the dependency section as a compile-time dependency and as a Test time dependency :
FYI:
That is how it is called in my code:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
It looks like IntelliJ hasn't imported the addition of these dependency. This usually means that the auto-import is disabled.
You can reimport your gradle file by clicking the reimport button in the gradle tab of IDEA. You can enable auto-import by clicking the Gradle Settings button in the gradle tab, and enabling "Automatically import this project on changes in build script files".
On a separate not, you don't need to declare testCompile if you also declare a dependency as compile.

Problem with gradle and external jar - jar not found

I have a problem with Gradle. I want to use an externally provided Jar: itext-2.1.7.js6.jar, it is a patched version used by JasperReports.
In the project structure, I have a /libs directory, containing 2 files: fonts.jar and itext-2.1.7.js6.jar
Part of my gradle.build file looks like this:
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.7.1'
implementation group: 'net.sf.jasperreports', name: 'jasperreports-functions', version: '6.8.0'
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
//implementation group: 'hu.blackbelt.bundles.itext', name: 'com.lowagie.itext', version: '2.1.7-1'
The last dependency is commented out cause I want to use the external JAR instead of the original iText.
When I am trying to run my app I get:
BUILD FAILED in 0s
1 actionable task: 1 executed
Could not find com.lowagie:itext:2.1.7.js6.
Required by:
project : > net.sf.jasperreports:jasperreports:6.7.1
What am I doing wrong? Everything is fine with my fonts.jar, so I think that it should be the same with iText, but it isn't...
As can be seen in the pom file of jasperreports, there is an explicit dependency on com.lowagie:itext:2.1.7.js6 which can also be found in a specific Jasper Reports repository
The reason this works transparently in Maven is that Maven will use the repositories defined in a pom file, while Gradle will not use them, as they could be a source of insecurity.
You have two options:
Add that repository, potentially using repository filtering to only serve these artifacts from there and then remove the file from libs
Add an exclude to jasperreportsso that it no longer tries to fetch that dependency. And instead the runtime code will use the version found in libs. You just forget about transitive dependency management in this case, for example when upgrading jasperreports and getting (or not) an updated version from their dependency declaration.

Gradle not downloading test dependency

I am looking to add a test dependency to my project which uses gradle. What I simply need is for gradle to download the dependency jar so I can import part of the package. What I need is the following package:
import org.springframework.security.test.*
So I edited my gradle file to contain
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
runtime('org.hsqldb:hsqldb')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test') // This is what I added to try and download the new dependency
}
I tried building the project after entering this. Unfortunately this didn't work and I cannot import org.springframework.security.test.* I then ran gradlew test which actually had some success and showed:
Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.pom
Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.jar
Though I have no idea where it downloaded to. Navigating to $HOME/.gradle/caches/modules-2/files-2.1/org.springframework.security I can see no sign of the downloaded package (and Idea doesn't recognise it in its external libraries). Running gradle build --refresh-dependencies didn't seem to work.
Any help would be very much appreciated.
Closes SO question I could find
I had the same issue, it works if a specific version is included in the dependency, such as:
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '5.1.6.RELEASE'

Categories

Resources