Gradle - how to specify javadoc location jar file for maven dependency? - java

I want to add local javadoc jar to maven dependency. Is it possible? If yes, how can I do it? The problem is that I've got maven dependency which contains transitive jars
dependencies {
compile 'org.eclipse.persistence:eclipselink:2.5.0'
}
gradle dependencies command returned this:
compile - Compile classpath for source set 'main'.
+--- org.eclipse.persistence:eclipselink:2.5.0
+--- org.eclipse.persistence:javax.persistence:2.1.0
\--- org.eclipse.persistence:commonj.sdo:2.1.1
Main dependency eclipselink contains javadoc for javax.persistence so I can't see javadoc hints in eclipse editor. What I want to do is to connect eclipselink javadoc to javax.persistence.
This is what I expect:
dependencies {
compile 'org.eclipse.persistence:javax.persistence:2.1.0' {
javadoc = <path to javadoc>
}
}

Problem solved. I've edited eclipse .classpath file using gradle eclipse plugin and it do what it should. This is the code:
eclipse {
classpath {
downloadSources=true
downloadJavadoc=true
file {
withXml {
def node = it.asNode()
// find eclipselink javadoc path
def eclipselinkPath = configurations.compile.find { it.absolutePath.contains('eclipselink') }
def javaxPersistenceJavadocPath = ""
node.each {
def filePath = it.attribute('path')
if (file(filePath) == file(eclipselinkPath)) {
javaxPersistenceJavadocPath = it.attributes.attribute.#value[0]
}
}
// add eclipselink javadoc path as attribute to javax.persistence
def javaxPersistencePath = configurations.compile.find { it.absolutePath.contains('javax.persistence') }
node.each {
def filePath = it.attribute('path')
if (file(filePath) == file(javaxPersistencePath)) {
it.appendNode('attributes').appendNode('attribute', [name:'javadoc_location', value:javaxPersistenceJavadocPath])
}
}
}
}
}
}
I know that it looks ugly but I didn't have more time to fight with that problem. BTW it wasn't the source of my problem (I've got problem with dependencies or gradle cache, I don't know yet).

Related

Failed to apply plugin [id 'forge']

This is a continuation of this question My initial issue has been solved, but a new one came after.
Following the tutorial mentioned in it, having solved a few errors, I now get an error when I try to run .\gradlew tasks:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1614-1.7.10-src\build.gradle' line: 18
* What went wrong:
A problem occurred evaluating root project 'forge-1.7.10-10.13.4.1614-1.7.10-src'.
> Failed to apply plugin [id 'forge']
> You must set the Minecraft Version!
> java.lang.NullPointerException (no error message)
How do I set the Minecraft version? (1.7.10 in this instance)
Edit to include build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
version = "1.0"
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "modid"
minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"
runDir = "eclipse"
}
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"
// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
Good day.
For minecraft version 1.7.10.
I was with the same problem, searching the forum in Japanese.
this link Forum
You have to modify the repositories and dependencies of the build.gradle and change the gradle-wrapper.properties to version 5.6.4.
As indicated in this link ForgeGradle-1.2
Contains an example to modify your build.gradle example
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url = "https://jcenter.bintray.com/" }
maven {
name = "forge"
url = "https://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath ('com.anatawa12.forge:ForgeGradle:1.2-1.0.+') {
changing = true
}
}
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
I made it work
Sorry, my English is very basic. I'm using a translator.
pls update the plugin to latest one . For reference check this link and link.
also try deleting the .gradle folder in your User Home and run it again.
I solved this by installing the 'Recommended' version of Forge 1.7.10 instead of the 'Latest'. Simple fix really, although I've already hit another wall.

How to create JAR from specific classes and use it with Gradle?

I have few Java classes that I want to use on different projects.
I don't want to move these classes in a dedicated project for now.
So I want to build a JAR with these classes, and be able to use it in my other projects, all with Gradle.
So here my JAR task (sources) and I publish it as an artifact :
task utilitiesJar(type: Jar) {
baseName = 'utilities'
version = '0.0.1'
includeEmptyDirs = false
from sourceSets.main.allJava
include "**\\common\\exceptions\\**"
include "**\\common\\json\\**"
include "**\\common\\logging\\**"
}
publishing {
publications {
utilities(MavenPublication) {
artifact utilitiesJar
groupId group
artifactId utilitiesJar.baseName
version utilitiesJar.version
}
}
repositories {
maven {
url 'my_URL'
}
}
}
I get it back with an other project :
repositories {
mavenCentral()
maven {
url 'my_URL'
}
}
...
compile (...)
...
Seems like the JAR is correctly imported (I can see it in "External Libraries" of IntelliJ, with all its classes), but I can't use it.
Maybe because the .class files are missing ?
I'm beginner in Java, maybe I missed something.
How can I create a JAR with only some classes and then use it ?
Ok so as said in comments, I have to include the builded .class files, I can't use external .java classes like this.
So my solution :
def utilitiesName = '...'
def utilitiesVersion = '0.0.1'
task utilitiesJar(type: Jar, dependsOn: classes) {
baseName = utilitiesName
version = utilitiesVersion
includeEmptyDirs = false
from sourceSets.main.output
include ("**\\common\\exceptions\\**\\*", "**\\common\\json\\**\\*", "**\\common\\logging\\**\\*")
}
task utilitiesSourcesJar(type: Jar, dependsOn: classes) {
baseName = utilitiesName
version = utilitiesVersion
classifier = 'sources'
includeEmptyDirs = false
from sourceSets.main.allJava
include ("**\\common\\exceptions\\**\\*", "**\\common\\json\\**\\*", "**\\common\\logging\\**\\*")
}
publishing {
publications {
utilities(MavenPublication) {
artifact utilitiesJar
artifact utilitiesSourcesJar
groupId group
artifactId utilitiesName
version utilitiesVersion
}
}
repositories {
maven {
url 'myURL'
}
}
}
Now I can use it and see the classes in my IDE.
PS : doing in this way is pretty dirty. Create a sub-project / a module, it's just the way how to do it, that's finaly what I did.

Gradle - Multiple Jar from single project

Context: To create multiple executable jar's from a single project - multiple package gradle project
Issue: I refer to the solution provided in Link, this helps in generating the jar in build->libs folder, but when I try executing the jar nothing happens
Note: Even if I make the package name same as java file name, the generated jar does not execute.
Also I notice the file size of all the jar's generated is the same. Hope the issue faced is clear & await inputs as to where I am making a mistake.
My Project Structure (illustrative purpose):
ProjectA
-src
--main
---java
----pkg1
-----pkgCalculator
------Calculator.java
-----pkgScale
------Scale.java
----pkg2
-----pkgMusicPlayer
------MusicPlayer.java
-----pkgVideoPlayer
------VideoPlayer.java
---resources
----fxml
----css
--test
---java
---resources
Gradle file (relevant portion below, rest as per the link above ):
artifacts {
archives jarPackage("pkgCalculator", "1.0"),
jarPackage("pkgScale","1.0"),
jarPackage("pkgMusicPlayer","1.0"),
jarPackage("pkgVideoPlayer","1.0")
}
After discussion with #iCoder, first part of the issue has been solved: the jarPackage function could not be reused "as is", and had to be adapted to support generic class/package layout:
def jarPackage(String jarName, String className, artifactVersion) {
if (artifactVersion == "" || artifactVersion == null) {
artifactVersion = "1.0.0"
}
return tasks.create("jar${jarName}", Jar) {
baseName = jarName
version = artifactVersion
def String pkgName = className.substring(0, className.lastIndexOf("."))
def String pkgDir = pkgName.replaceAll("\\.", "/")
def String clazzName = className.substring( className.lastIndexOf(".") +1 )
from(sourceSets.main.output) {
include "$pkgDir//**"
}
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes "Implementation-Title": "$clazzName",
"Implementation-Version": "$version",
"Main-Class": "$pkgName.$clazzName"
}
}
}
artifacts {
archives jarPackage("calculator", "pkg1.pkcalculator.Calculator" , "1.0.0")
}
Another issue remains, not related to Gradle but to JDK 11 linkage problem: #iCoder you should open another question for that remaining problem, if not fixed yet.

Include additional Sources for recompile in gwtSuperDev Task

I use the GWT Gradle Plugin. I have a second project which I included in my main project with:
dependencies {
compile(project(':core-project')) {
transitive = false
}
}
I have also created a settings.gradle which contains
includeFlat 'core-project'
The core-project is a library project. When I run gradle gwtSuperDev and change files in my main project recompile takes place but not if I change files in my core-project.
How can I make that the core-project sources are also recompiled in SuperDevMode when they have changed?
Depending on how your gradle dependencies are organized, you can simply add their source-files to the gwt section of your build.gradle file.
I have something like this in my build file:
gwt {
gwtVersion = '2.7.0'
if (System.getProperty('devmode') != null) {
modules = ['dk.logiva.invoice.autoaccount.gwt.AutoAccountAdminDev']
compiler {
style = 'PRETTY';
strict = true;
}
// include sources from inherited module
src += project(':invoice:gwt:gwt-common').files('src/main/java')
} else {
modules = ['dk.logiva.invoice.autoaccount.gwt.AutoAccountAdmin']
}
devWar = file("${buildDir}/war")
maxHeapSize = "3G"
}
...
dependencies {
compile project(':invoice:gwt:gwt-common')
...
}

Gradle scala class already defined with combined Java compilation

I have the following scala compilation issue
scala -> depends upon java source
java source -> depends upon scala source
My scala code is in src/main/scala
My java code is in src/main/java
I cant change this code so I need to compile this with gradle and it currently compiles with JRuby just fine.
I have read the following posts on how to solve this issue:
http://forums.gradle.org/gradle/topics/how_to_compile_a_java_class_that_depends_on_a_scala_class_in_gradle
http://forums.gradle.org/gradle/topics/how_to_compile_a_java_class_that_depends_on_a_scala_class_in_gradle
I added this to my build:
ext {
baseName = 'd2'
description = 'Divisional IVR.'
combinedSources = "$buildDir/combined-sources"
}
apply plugin: 'scala'
compileScala.taskDependencies.values = compileScala.taskDependencies.values - 'compileJava'
compileJava.dependsOn compileScala
sourceSets.main.scala.srcDir "$combinedSources"
sourceSets.main.java.srcDirs = []
I tried to copy all the scala and java files to one location:
compileScala.dependsOn{
copyAllSourceFiles
}
task copyAllSourceFiles(type:Copy) {
description = 'Copy All Source Files.'
from('src/main/java') {}
from('/src/main/scala') {}
into combinedSources
includeEmptyDirs = false
}
But now I get an error:
[ant:scalac] Compiling 18 source files to C:\usr\git_workspaces\xivr\d2\target\classes\main
[ant:scalac] Compiling 18 scala and 196 java source files to C:\usr\git_workspaces\xivr\d2\target\classes\main
[ant:scalac] C:\usr\git_workspaces\xivr\d2\target\combined-sources\com\comcast\ivr\d2\actors\AlternateAniWithAccountActor.scala:9: error: AlternateAniWithAccountActor is already defined as class AlternateAniWithAccountActor
It almsot seems like scalaCompile sees $combinedSources and 'src/main/scala'
It almsot seems like scalaCompile sees $combinedSources and 'src/main/scala'
That's how you configured it: src/main/scala is the default, and you added "$combinedSources". To override the default, use sourceSets.main.scala.srcDirs = [combinedSources].
In any case, you don't have to (and shouldn't) copy sources around. Here is one solution that neither requires copying nor reconfiguring of task dependencies:
sourceSets.main.scala.srcDir "src/main/java"
sourceSets.main.java.srcDirs = []
Now, your Java and Scala code will get joint-compiled, and can depend on each other arbitrarily.
PS: Instead of "$combinedSources", use combinedSources.
gradle.properties
theVersion=2.1
theSourceCompatibility=1.7
theScalaVersion=2.10.3
build.gradle
apply {
plugin 'scala'
plugin 'java'
plugin 'idea'
}
ext {
scalaVersion = theScalaVersion
}
sourceCompatibility = theSourceCompatibility
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
dependencies {
compile "org.scala-lang:scala-library:$theScalaVersion"
compile "org.scala-lang:scala-compiler:$theScalaVersion"
}
sourceSets {
main.scala.srcDirs = ["src/main/scala", "src/main/java"]
main.java.srcDirs = []
}

Categories

Resources