JavaDoc and Jar fails

Hi,

Following code does not create the JavaDoc output or the jar files.

I am looking to create a class, src, and docs jars separately.

Why does this not produce any build files in GGTS and also does not generate Docs and Jars? Can you give a working example.

NB: this project does not have any dependencies. Also I am using GGTS.

Suminda

apply plugin: 'java'
apply plugin: 'eclipse'
  sourceCompatibility = 1.7
targetCompatibility = 1.6
version = '2.0'
  jar {
 manifest {
   attributes 'Lib': 'Sakrio BoxOnce', 'Version': version
 }
}
  sourceSets {
 main {
   java {
     srcDir 'src'
   }
 }
}
  task genJavadocs(type: Javadoc) {
 source = sourceSets.main.allJava
 }
  uploadArchives {
 repositories {
  flatDir {
    dirs 'jars'
  }
 }
}

You didn’t really configure your build to produce multiple JAR files. To achieve this you can create additional tasks of type Jar to bundle source files and Javadocs.

task sourcesJar(type: Jar) {
    classifier 'sources'
    from sourceSets.main.allSource
}
  task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier 'javadoc'
    from javadoc.destinationDir
}
  artifacts {
    archives sourcesJar
    archives javadocJar
}

As you don’t really customize your Javadocs, you will not need to define your own Javadoc task. It is provided by the Java plugin out-of-the-box.

Many thanks for the response. I am using GGTS 3.4.

I get Build Successful but non of the build is run. The java source files are not compiled. I do not get any class files in the build directory of the Jars of the Docs.

I really cannot figure out why.

BUILD SUCCESSFUL
  Total time: 1.541 secs
apply plugin: 'java'
apply plugin: 'eclipse'
  sourceCompatibility = 1.7
targetCompatibility = 1.6
  version = '2.0'
    sourceSets {
  main {
   java {
      srcDir 'src'
   }
  }
}
  task classJar(type: Jar, dependsOn: compileJava) {
 classifier 'classes'
 from javadoc.destinationDir
}
  task sourcesJar(type: Jar) {
    classifier 'sources'
    from sourceSets.main.allSource
}
  task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier 'javadoc'
    from javadoc.destinationDir
}
  artifacts {
  archives classJar
    archives sourcesJar
    archives javadocJar
}
  uploadArchives {
  repositories {
    flatDir {
     dirs 'jars'
    }
  }
}

Also is there a way to pack all included projects (settings.gradle) into jars also

You don’t have to declare the task classJar. This functionality is already provided by the Java plugin. Also, in your case it would try to bundle the Javadocs as indicated by javadoc.destinationDir. I’d also define the sourceSet customization as follows:

sourceSets {
    main {
        java {
            srcDirs = ['src']
        }
    }
}

If your source files sit in the src directory, then the command "gradle build: should create all three JAR files. Based on your question about “settings.gradle” it sounds as if you are working on a multi-project build and not a single project build. Is that the case?

Can you provide us with an example project preferably on GitHub? That’ll make it easier to troubleshoot your issue.

Many thanks again for the response. This is a closed project thus cannot share much in Github.

BTW, how can you set alternate different directories in Gradle 2.0

I have shared a toy project which shows the issue. I am using GGTS 3.4.

apply plugin: 'java'
apply plugin: 'eclipse'
  sourceCompatibility = 1.6
targetCompatibility = 1.6
  version = '2.0'
    sourceSets {
 main {
  java {
   srcDir = ['src']
  }
 }
 output {
  classesDir = ['bin']
 }
}
  println sourceSets.main.output.classesDir
  task classJar(type: Jar, dependsOn: compileJava) {
 classifier 'classes'
 from sourceSets.main.output.classesDir
}
  task sourcesJar(type: Jar) {
 classifier 'sources'
 from sourceSets.main.allSource
}
  task javadocJar(type: Jar, dependsOn: javadoc) {
 classifier 'javadoc'
 from javadoc.destinationDir
}
  artifacts {
 archives classJar
 archives sourcesJar
 archives javadocJar
}
  uploadArchives {
 repositories {
  flatDir {
   dirs 'jars'
  }
 }
}

I get the following output.

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "srcDir" on "source set main", value: "[src]".
Deprecated dynamic property: "classesDir" on "source set output", value: "[bin]".
C:\WorkSpace\workspace-ggts-3.3.0.RELEASE\GradleTest\build\classes\main
  BUILD SUCCESSFUL
  Total time: 0.443 secs

But build is not executed. Non ot the tasks is executed.

This toy project is shared in : https://bitbucket.org/sirinath/gradletest

Once this is sorted perhaps we can try to troubleshoot including other projects from the settings file.

You had a typo in sourceSets.main.java.srcDirs. You were missing an “s”. I also corrected some of your logic. After executing “gradle build” you will find your generated JAR files under build/libs.

To your question “BTW, how can you set alternate different directories in Gradle 2.0”: The version property assigns the version to your project and not the version of Gradle. Plus you are already setting different source and classes directories.

apply plugin: 'java'
apply plugin: 'eclipse'
  sourceCompatibility = 1.6
targetCompatibility = 1.6
  version = '2.0'
  sourceSets {
 main {
  java {
   srcDirs = ['src']
  }
      output.classesDir = 'bin'
 }
}
  task sourcesJar(type: Jar) {
 classifier 'sources'
 from sourceSets.main.allSource
}
  task javadocJar(type: Jar, dependsOn: javadoc) {
 classifier 'javadoc'
 from javadoc.destinationDir
}
  artifacts {
 archives sourcesJar
 archives javadocJar
}
  uploadArchives {
 repositories {
  flatDir {
   dirs 'jars'
  }
 }
}

I updated it (in the test repo also) but still no output.

I want to place the classes in ‘bin’ (jar of classes in ‘jars’) and javadocs in ‘docs’ and jars in ‘jars’.

BTW, does Gradle create the needed directories to place the artefacts? Any way I have created them including ‘build/libs’.

Uploaded into the repo.

Works fine for me with Gradle 1.8. Not sure what wrong on your end. BTW: You moved output.classesDir = ‘bin’ into the wrong spot. Check my original posted listing. You do not need to create nor check-in the output directories. Gradle creates the directories for you.

An important part of learning Gradle is to get into the documentation (online docs, DSL guide). You can easily reconfigure the output directories.

I made the correction. But still the compile, javadoc, and jar task do not seam to have run.

I am using GGTS 3.4.RELEASE with

Gradle IDE 3.4.0.201310051517-RELEASE

I will be out of office for 2 weeks. Will touch base when I come back.

Running this on command line should just work fine. Not sure about GGTS. That’s probably a totally different issue.

Benjamin, how come your “sourcesJar” task is not explicitly declared to “dependsOn classes”? But you explicitly declare that “javadocJar” “dependsOn javadoc”? For me, leaving sourcesJar without no explicit dependsOn declaration work and I think it is 'cause Gradle know that already from the “from” statement. But, I can not leave out the dependsOn declaration from the javadocJar task. If I do that, the built jar will be empty. How come sourcesJar work without dependsOn, but javadocJar fail?

you don’t need to compile source files to create a jar containing source files. So no dependsOn is needed. The sources are there, and all the task needs to do is putting them in a jar file. To generate a jar containing the javadoc, the javadoc must first be generated, hence the dependsOn javadoc.

Yeah that sounds pretty straight forward =) Thank you so much!