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

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.

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 to add Lombok to a Gradle Java Library project?

I tried this:
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'io.freefair.lombok' version '3.8.4'
}
But I'm getting this error:
Unable to load class 'org.gradle.api.plugins.quality.FindBugsPlugin'.
This is an unexpected error. Please file a bug containing the idea.log file.
Lombok is available in maven central, so telling Gradle to download
lombok is easy.
The Lombok Gradle Plugin There is a plugin for gradle that we recommend you use; it makes deployment a breeze, and makes it easy to
do additional tasks, such as delomboking. The plugin is open source.
Read more about the gradle-lombok plugin.
Gradle without a plugin If you don't want to use the plugin, gradle has the built-in compileOnly scope, which can be used to tell
gradle to add lombok only during compilation. Your build.gradle will
look like:
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}
Remember that you still have to download lombok.jar (or find it in
gradle's caches) and run it as a jarfile, if you wish to program in
eclipse. The plugin makes that part easier.
Official site lombok -> https://projectlombok.org/setup/gradle

Gradle unable to resolve Dropwizard 1.2.0

I would like to use the most recent version of Dropwizard, unfortunately I cannot, because Gradle is unable to resolve it.
Here is my build.gradle file:
group 'com.gaboratorium'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
ext {
dropwizardVersion = '1.2.0'
}
repositories {
mavenCentral()
}
dependencies {
// Application
implementation "io.dropwizard:dropwizard-core:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-db:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-jdbi:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-auth:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-migrations:${dropwizardVersion}"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Things I have tried:
Using jcenter repository instead
IntelliJ > Invalidate caches / Restart
Using an older version instead; the only one I could make work was 0.8.2
Did anyone experience something similar?
As it turned out my issue was that proxying was set up in my IntelliJ thanks to a previous project, which I was not aware of. However during my research for the problem I have found some relevant answers to this question, which I am going to place here for future reference:
IntellijIDEA not recognizing classes specified in Maven dependencies
Maven - can't download fasterxml.jackson
Gradle build doesn't download dependencies

Javax.servlet dependency does not work

I am creating a Gradle project in Intellij to improve my skills because I am learning. Previously, I created the same project with Maven and It is working well.
My project is this:
Project
How you can see in the image "HttpServlet" is not recognised and I don't know why because I have the dependency and apparently everything is correct, here is my build.gradle with the dependency:
group 'com.aprendiendo.java'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
In the first image It can be seen how in the Gadle Project menu -> Dependences folder is javax.servlet.... but however It does not work because I can't use anything of Java Servlet API (Classes, etc...), how you can see in the image of my project which I put before.
I have revised everything and I dont know what is happening.
I tried a similar setup on my IntelliJ version and everything actually ended up working ok. You can try NOT using the fully qualified name in the extension. Use
public class Servlet extends HttpServlet
instead of
public class Servlet extends javax.servlet.http.HttpServlet
Then hover over HttpServlet with your mouse and see if IntelliJ autosuggest an import. If it does then you can then use Alt + Enter to complete the import. This may juice IntelliJ to recognize the dependency. You can also try Build --> Make Project to see if recognizes.
You may also want to check under File --> Project Structure and select the libraries node. Look and see if the dependencies are listed: javax:servlet-api:3.1.0, junit:junit:4.11, org.hamcrest:hamcrest-core:1.3.
I did only test this on a later version of IntelliJ 2016, but it should work. Feel free to post back comments/questions.

Gradle subproject jar and add to Eclipse referenced libraries

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

Categories

Resources