Gradle 2.0 generates ivy.xml seemingly by default - java

I currently trying out gradle and am using the java plugin.
However every time I build, I find that the ivy.xml is getting generated as well.
I have not included any other plugin such as the 'ivy-publish' or any other.
Is this gradle's default behaviour?
I can simply ignore it but I was curious regarding why.
Edit: 10Aug2014
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
sourceSets {
mainTwo {
java {
srcDir 'src'
}
}
}
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
}
uploadArchives {
repositories {
flatDir {
dirs 'dist-two'
}
}
}
task all (dependsOn : [uploadArchives,jar]) {
println 'Done!'
}
task hello << {
println 'Hello Earth'
}

Related

Gradle dependency downloads but packages aren't available in project

I published a small library of mine to a free maven hosting service, and am using that package in another project. I've done this before without issue but something isn't working this time.
Gradle finds the file just fine, and downloads it I assume. I know this because any change to the URL, package name, or version, and Gradle throws the "can't find the dep in any of these places" error.
However, any import of the packages in this JAR error, saying it can't find the package. IntelliJ, when I refresh gradle deps, also doesn't show my library in the "External Libraries" section.
Here's my gradle.build for the project I'm using the library in:
apply plugin: 'java'
repositories {
maven { url = 'https://repo.repsy.io/mvn/viveleroi/tileowner' }
}
group = project.property("group")
version = project.property("version")
dependencies {
compileOnly 'network.darkhelmet.tileowner:tileowner:1.0.0'
}
compileJava {
options.compilerArgs += ["-parameters"]
options.fork = true
options.forkOptions.executable = 'javac'
}
The test class:
import network.darkhelmet.tileowner.TileOwner;
public class Demo {}
Gradle says it's on the classpath:
compileClasspath - Compile classpath for source set 'main'.
\--- network.darkhelmet.tileowner:tileowner:1.0.0
compileOnly - Compile only dependencies for source set 'main'. (n)
\--- network.darkhelmet.tileowner:tileowner:1.0.0 (n)
I've downloaded the published jar of my library from that repository, unzipped it, and have confirmed all files are in there as expected.
Here's the build.gradle of my library project:
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
dependencies {
classpath group: 'com.github.rodionmoiseev.gradle.plugins', name: 'idea-utils', version: '0.2'
}
}
plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "xyz.jpenilla.run-paper" version "1.0.6"
id 'maven-publish'
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'idea-utils'
apply plugin: 'checkstyle'
processResources {
filter ReplaceTokens, tokens: [
"apiversion": project.property("apiversion"),
"version" : project.property("version")
]
}
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://repo.aikar.co/content/groups/aikar/" }
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
}
group = project.property("group")
version = project.property("version")
targetCompatibility = sourceCompatibility = JavaVersion.VERSION_17
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
implementation 'co.aikar:acf-bukkit:0.5.0-SNAPSHOT'
}
compileJava {
options.compilerArgs += ["-parameters"]
options.fork = true
options.forkOptions.executable = 'javac'
}
jar {
actions = []
dependsOn = []
dependsOn('shadowJar')
}
shadowJar {
relocate 'co.aikar.commands', 'network.darkhelmet.tileowner.acf'
relocate 'co.aikar.locales', 'network.darkhelmet.tileowner.locales'
}
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
}
}
repositories {
maven {
name = 'repsy'
url = 'https://repo.repsy.io/mvn/viveleroi/tileowner'
credentials(PasswordCredentials)
}
}
}

Javafx 10 or older for download to create a runnable jar file

I am looking for javafx 10 or newer. I currently have javafx-sdk-11 and trying to make my programme a single runnable jar file, but apparently since javafx 11, that option isn't available anymore.
So I have to go to the terminal and type the following line to run it :
java --module-path /path/to/javafx/javafx-sdk-11.0.2 or another/lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web -jar /path/to/GUI_Music_Gen.jar
Since I can't find older versions of javafx available for download, I ask for your help. If anybody can help me, let me know. Thanks in advance.
Btw, I don't know if this will be an issue for compatibility, but I run macOS X.
I would recommend using dependency management like grade or maven to run JavaFX and Build a working Jar.
I can offer you this build.gradle for a working JavaFX project:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.7.0'
classpath 'org.openjfx:javafx:11'
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
sourceCompatibility = 11
targetCompatibility = 11
repositories {
jcenter()
mavenCentral()
}
// configure here
mainClassName = "your.app.main"
publishing {
publications {
mavenAar(MavenPublication) {
from components.java
afterEvaluate {
artifact javadocJar
artifact sourcesJar
}
}
}
}
javafx {
version = "11"
modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}
sourceSets {
main.java.srcDir "src/main/java"
main.resources.srcDir "src/main/resources"
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:27.0.1-jre'
testImplementation 'junit:junit:4.12'
// use java fx just like a regular dependency :)
implementation 'org.openjfx:javafx:11'
compile group: 'org.openjfx', name: 'javafx', version: '11.0.2'
}
// important Configure your project
jar {
manifest {
attributes(
'Main-Class': 'your.app.main'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
]
println options.compilerArgs
}
}
Just replace "your.project.main" with your actual main class and everything should run fine.
Also it is really important that your Main class does not extend from Application.
It should only Launch the Application.

Can't compile Java class when calling Clojure code

Adding clojure to an already existing gradle java project
I have a Java project that I want to start trying to add some Clojure to, but I'm hitting a few issues. I'm using the IntelliJ IDEA with the Cursive for Clojure IntelliJ plugin.
I am also using the gradle-clojure plugin for Clojure. My Java classes recognise and can call my Clojure code, but my Java code will no longer compile because at compile time it can no longer see my Clojure code.
Do I need to add an extra step in my build.gradle? Do I need to compile my Clojure separate and manually before trying to compile Java?
Any help would be greatly appreciated.
Environment
gradle-clojure v0.3.1 gradle v4.4.1Java v1.8 Intellij IDE on MacOS High Sierra
Stacktrace <> Task :compileJava FAILED java:8: error: cannot find symbol import com.example.clojure;
You can use Netflix's Clojure Wrapper, nebula.clojure.
Here is an example of a Gradle Build script for a project that uses Java and Clojure:
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "com.netflix.nebula:nebula-clojure-plugin:4.4.0"
}
}
plugins {
id "nebula.clojure" version "4.4.0"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'com.demo'
def artifactName = 'demo-service'
version = latestRepoTag()
static def latestRepoTag() {
def cmd = "git describe --abbrev=0"
def proc = cmd.execute();
return proc.text.trim();
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext['spring-restdocs.version'] = '1.2.1.RELEASE'
ext {
springCloudVersion = 'Dalston.SR4'
}
compileJava {
classpath = project.files(
project.compileClojure.outputs,
classpath
)
}
compileClojure {
jvmOptions {
jvmArgs '-Djava.awt.headless=true'
}
}
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
jar {
baseName = "${artifactName}"
version = latestRepoTag()
}
clojure.aotCompile = true
configurations{
dev
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR3'
}
}
dependencies {
compile 'org.clojure:clojure:1.6.0'
compile('com.google.guava:guava:19.0')
compile("commons-io:commons-io:2.5")
compile "org.apache.pdfbox:pdfbox:2.0.0-RC3"
compile("org.apache.commons:commons-lang3:3.0")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compileOnly("org.projectlombok:lombok:1.16.6")
runtime('com.h2database:h2:1.4.190')
runtime("com.ingres.jdbc:iijdbc:10.0-4.0.5")
runtime('org.apache.commons:commons-dbcp2:2.1.1')
runtime('org.postgresql:postgresql:9.4.1209')
dev("org.springframework.boot:spring-boot-devtools")
testCompile('com.jayway.jsonpath:json-path')
testCompile('com.jayway.jsonpath:json-path-assert:2.2.0')
testCompile('com.google.code.gson:gson:2.8.1')
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc:1.2.1.RELEASE")
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.dev
systemProperties = System.properties
jvmArgs = ["-client", "-Dsun.net.inetaddr.ttl=60", "-Djava.security.egd=file:/dev/./urandom"]
environment = [
'spring_profiles_active': 'beta,fast_discovery'
]
}
Here is a link to the plugin on Gradle's plugin documentation site:

Gradle fail to download Kotlin repository

I'm building Kotlin simple Hello-Worl using Gradle
my build.gradle is:
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.3.1/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Kotlin
apply plugin: 'kotlin'
/*
plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.60"
}
*/
buildscript {
ext.kotlin_version = '1.1.60'
// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
// jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.12'
}
kotlin {
experimental {
coroutines 'enable'
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
compileKotlin {
kotlinOptions {
suppressWarnings = true
}
}
and Main.kt is:
fun main(args: Array<String>) {
println("kotlin!")
}
upon running Gradle buil, I got the below error:
Notes:
- I'm new to gradle so built it as below 2 steps:
Step 1:
Step 2:
UPDATE
As per the first answer, I tried getting the files locally, I created another folder named lib and downloaded the *.jar files into it, so I got the gradle.build as below:
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath fileTree(include: ['*.jar'], dir: 'libs')
classpath files('kotlin-gradle-plugin-1.1.60.jar')
}
}
apply plugin: 'kotlin'
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile name: 'kotlin-stdlib-1.1.60'
testCompile 'junit:junit:4.12'
}
kotlin {
experimental {
coroutines 'enable'
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
compileKotlin {
kotlinOptions {
suppressWarnings = true
}
}
Below the revised structure and new error I got:
UPDATE
U copied all the required repositories .jar and .pom to folder:
C:\Users\.m2\repository\org\jetbrains\
I copied for example:
...\kotlin\kotlin-std\1.1.60\kotlin-stdlib-1.1.60.jar
And
...\annotations\13.0\annotations-13.0.jar
And used
mavenLocal()
But still getting the same error :(
I found the issue to be with our company proxy that prevented such thing, so I solved the issue by downloading the required repository in my hole laptop then copied them to the company one.
First, I created a separate folder, named it jars.
After that I downloaded the required file from here and saved it in the jars folder.
Then I installed it into the local repository using the command:
mvn install:install-file -Dfile=utility.jar -DgroupId=com.company -DartifactId=utility -Dversion=0.0.1 -Dpackaging=jar
Such as:
mvn install:install-file -Dfile=kotlin-stdlib-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-stdlib -Dversion=1.1.60 -Dpackaging=jar
Notes:
To do the above correctly, the maven is required to be downloaded from here and added to the path.
And command above is required to be run from the jars folder, that contains the downloaded repository:
Then I found that the repository had been downloaded into C:\Users\<user>\.m2\ folder:
After copying them into my office laptop, I called them from the mavenLocal():
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile ("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
}
UPDATE
To download the full repository in one shoot instead of downloading the required files one by one, then the following command can be used:
mvn dependency:get -DrepoUrl=something -Dartifact=group:artifact:version
Such as:
mvn dependency:get -DrepoUrl=https://mvnrepository.com/artifact/org.jetbrains.kotlin -Dartifact=org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.60
For some reason 3 files failed to be downloaded, so I got them downloaded manually and installed as per the initial explanation,the files are:
org.jetbrains.kotlin:kotlin-android-extensions:jar:original:1.1.60 => here
org.jetbrains.kotlin:kotlin-compiler-runner:jar:original:1.1.60 => here
org.jetbrains.kotlin:kotlin-build-common:jar:tests:1.1.60 => here
and got them installed using the below commands:
mvn install:install-file -Dfile=kotlin-android-extensions-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-android-extensions -Dversion=1.1.60 -Dpackaging=jar
mvn install:install-file -Dfile=kotlin-compiler-runner-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-compiler-runner -Dversion=1.1.60 -Dpackaging=jar
mvn install:install-file -Dfile=kotlin-build-common-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-build-common -Dversion=1.1.60 -Dpackaging=jar
Considering all the above done, the below build.gradle worked perfectly for me:
// set up the kotlin-gradle plugin
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
// apply the kotlin-gradle plugin
apply plugin: "kotlin"
// add kotlin-stdlib dependencies.
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
//dependencies from a remote repositor
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//local file, that are not coming from repository, let's say my own jar files
compile files('libs/Display.jar')
compile fileTree(dir: 'libs', include: '*.jar')
}
jar {
manifest {
//Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
attributes ('Main-Class': 'MainKt', "Implementation-Title": "Gradle",
"Implementation-Version": 1)
}
// NEW LINE HERE !!!
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
kotlin {
experimental.coroutines 'enable'
}
compileKotlin {
kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
kotlinOptions.suppressWarnings = true
}

Could not find or load main class when a specific package is used

I need to use browsermob-proxy.
My project can be run from IDE, but when I build it by gradle and add compile 'net.lightbody.bmp:browsermob-core:2.1.4' into my gradle config file the jar is successfully built (there are no any errors), but the main function is not loaded:
#gradle clean jar
#java -jar build/proxy-0.1.jar
"Error: Could not find or load main class myproject.MainKt"
If I add this utility to my existed package (that could be built and run as a fat jar) it can not be built.
What am I doing wrong?
Is it possible that it is bug in browsermob-proxy?
Thanks.
My gradle file is the following:
group 'proxy'
version '0.1'
buildscript {
ext.kotlin_version = '1.1.3'
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlin_version
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M6'
}
}
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'org.junit.platform.gradle.plugin'
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre8'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version'
compile 'net.lightbody.bmp:browsermob-core:2.1.4'
testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0-M6")
testCompile("org.junit.jupiter:junit-jupiter-params:5.0.0-M6")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0-M6")
}
jar {
destinationDir = file('build/')
manifest {
attributes 'Main-Class': 'myproject.MainKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

Categories