Gradle dependency downloads but packages aren't available in project - java

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)
}
}
}

Related

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:

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) } }
}

Eclipse error during resolving gradle dependency

I have added the dependency com.sun.mail:javax.mail:1.5.4 to build.gradle, but Eclipse doesn't resolve this dependency and throws this error
Illegal entry in Gradle Dependencies: D:/Programs/Eclipse/unresolved dependency - com.sun.mail javax.mail 1.5.4 PluginName Unknown org.springsource.ide.eclipse.gradle.core.classpathcontainer
I tried to clean & rebuild the project, refresh dependencies many times, but I still get the same error and the dependency doesn't download. What can be wrong?
My build.gradle file:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'PluginName',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
maven {
name 'Sponge maven repo'
url 'http://repo.spongepowered.org/maven'
}
}
dependencies {
compile 'org.spongepowered:spongeapi:2.1-SNAPSHOT'
compile 'com.sun.mail:javax.mail:1.5.4'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
I definietly don't know why, but It started to work and dependency just downloaded.

Issues with Proguard using Gradle in a non-Android project

I am trying to obfuscate the code of my Java project with Proguard. This project has been created on Intellij and is configured with Gradle 2.2.1. There is a proxy on the computer I work on so Intellij can not access the Internet.
I tried for hours to find a simple example to obfuscate my code.
I tried to do :
task proguardTask(type: proguard.gradle.ProGuardTask) { println "ha"}
task proguardTask(type: proguard.gradle.ProGuardTask) << { println "ha"}
and I got an exception every time :
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':proguardTask'.
> Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at proguard.ClassPath.get(ClassPath.java:77)
Here's my build.gradle file:
// Configuration des library java
project.ext.LIBJava = [
"project1",
"project2", "project2",
"project2_OS", "project2_UI",
"project3",
"project3_Windows"
]
//----------------------------------------------------------------------------------------------------------
ext.buildOnline = false
ext.buildOnlineMapsforge = false
ext.buildAndroid = false
//----------------------------------------------------------------------------------------------------------
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
buildscript {
repositories {
mavenLocal()
mavenCentral()
flatDir dirs: 'C:/Path/To/Proguard/proguard-5.1/lib'
}
dependencies {
classpath ':proguard'
}
}
def filterProjects(filter) { return subprojects.findAll { project -> filter.contains(project.name) } }
allprojects {
group = 'org.libWin'
version = '0.1.1'
}
// Configuration injection for all subprojects
subprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
//----------------------------------------------------------------------------------------------------------
task proguardTask(type: proguard.gradle.ProGuardTask) {
println "ha"
}
configure(filterProjects(project.LIBJava)) {
apply plugin: 'java'
dependencies {
if (buildOnline) { // On-line
testCompile group: 'junit', name: 'junit', version: 4.11 // "$jUnitVersion"
}
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
}
Does anyone know where the problem comes from ? How to obfuscate easily my code with Proguard using Gradle ?
Thanks.
You must specify injars in your Proguard task.
Example:
task proguard(type: proguard.gradle.ProGuardTask) {
injars "build/libs"
}
I could obfuscate with proguard a non-Android project with the plugin proguard-gradle .
Specify your proguard configurations (keep options) in a file
Specify input & output jars
Specify the dependencies (jars) which your project referred to.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.0.3'
classpath 'net.sf.proguard:proguard-base:6.0.3'
}
}
def dependsDir = "${buildDir}/libs/dependencies/"
def outputJar = "${buildDir}/libs/${rootProject.name}.jar"
task proguard(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.conf'
injars "${outputJar}"
outjars "${buildDir}/libs/${rootProject.name}_proguard.jar"
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
libraryjars "${dependsDir}"
}
Add the above gradle task to your build.gradle
Execute gradle proguard

Spring Boot Multi Module Gradle Build - Multiple "Fat Jars"

our spring-boot project looks like the following
project
|__ build.gradle
|__ settings.gradle
|__ module_a
|__ module_b
|__ ...
|__ module_a
|__ module_b
module_a contains only the SpringApplication class and a file application.properties
Running ./gradlew build works fine, but the problem is, for every module (about 10) gradle generates a fat jar including all dependencies.
We want to only have one far jar (in module a)
buildscript {
ext {
springBootVersion = '1.2.0.RELEASE'
springLoadedVersion = '1.2.0.RELEASE'
}
repositories {
// NOTE: You should declare only repositories that you need here
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.springframework:springloaded:${springLoadedVersion}")
}
}
allprojects {
group = "example.group"
version = "0.0.1"
repositories() {
mavenCentral()
}
}
subprojects {
apply plugin: "groovy"
apply plugin: "eclipse"
eclipse {
classpath {
containers.remove("org.eclipse.jdt.launching.JRE_CONTAINER")
containers "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
}
}
apply plugin: "idea"
apply plugin: "java"
apply plugin: "spring-boot"
mainClassName = "MainClassName"
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
}
}
task wrapper(type: Wrapper) { gradleVersion = '2.2' }
We tried adding the options
jar.enabled = false
bootRepackage.enabled = false
in the subprojects section, but after that, the project wont comile any longer.
Rather than applying the Spring Boot plugin to every sub-project, you could apply it only to module_a:
project(':module_a') {
apply plugin: 'org.springframework.boot'
}

Categories