IntelliJ IDEA not copying resources on build - java

My build output is out/production/classes.
Java files get compiled into classes just fine and get put on out/production/classes/[packageName], but resources aren't copied. As far as I know they should go directly inside the out/production/classes directory.
If relevant, I'm using Java 11, Spring Boot and Gradle.
This is my build.gradle
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'net.impfox'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// hidden
}
And my Compiler settings:
What could be the cause for my resources not being copied to the output directory and how can I fix this?

If someone is having this issue in Maven. I fixed it by changing the
<packaging>pom</packaging>
to
<packaging>jar</packaging>
In pom.xml
I copied a pom.xml from a maven moduler project (in main pom.xml it uses pom as packaging). Guess I learned my lesson.

I was not able to find the root problem, but I've got a guess. I renamed the entire project before and replaced every occurence of the old project name with the new one. Maybe some internal cache still had the old name inside?
I ended up cloning the project from version control, now it works.

Related

Adding custom maven dependency to gradle project [duplicate]

This question already has answers here:
How to add a Maven project as a Gradle dependency?
(3 answers)
Closed 2 years ago.
I have created dependency jar using maven project but now i have to add this maven dependency into my gradle project.
Depencency available in my .m2 directory
Am getting the below error from intellij .
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Cannot convert URL 'com.example.auth.security:common:0.0.1-SNAPSHOT.jar' to a file.
Please find my build.gradle file
plugins {
id 'org.springframework.boot' version '2.1.16.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.example.auth'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation files('com.example.auth.security:common:0.0.1-SNAPSHOT.jar') --> getting error on this line.
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
compileOnly 'org.projectlombok:lombok'
implementation('io.jsonwebtoken:jjwt:0.9.1')
}
Update 1
A problem occurred evaluating root project 'auth-center'.
> Supplied String module notation '0.0.1-SNAPSHOT' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'.
You will need to add a local maven repository like this
repositories {
maven { url new File(pathToYourM2Directory).toURI().toURL() }
}
Additionally the declaration of the dependency is not correct. It should be
dependencies {
implementation group: 'com.example.auth.security', name: 'common', version '0.0.1-SNAPSHOT'
}
You can as well fix the files dependency. However using a local maven repo is more sustainable as by resolving artifacts this way it is transparent for the build process if an artifact is resolved locally or remote.
Can't comment since I don't have sufficient reputation. I believe you shouldn't be trying to add the maven dependency to the gradle project. Instead, host the maven dependency elsewhere and configure gradle to pull dependencies from there. For reference, you can take a look at this answer
How to add a Maven project as a Gradle dependency?
This is another way to import your custom java library(.jar).
What you need to do is that first, make a folder wherever you want under your project, in my case /src/lib, and put JAR file into that folder. Then, write down the below code into your Gradle file.
dependencies {
//Library Auto Implement
//Replace with your folder URI
implementation(fileTree("./src/lib"))
}
Then Gradle will implement your JAR files from that folder, and you are ready to go.

IntelliJ IDEA Gradle project not recognizing/locating Antlr generated sources

I'm using Antlr in a simple Kotlin/Gradle project, and while my Gradle build is generating Antlr sources, they are not available for importing into the project.
As you can see (on the left), the classes (Lexer/Parser, etc.) are being generated. I have also configured this generated-src/antlr/main directory as a Source Root. Most questions I see list this as a solution, but I've already done it.
The issue persists after multiple rebuilds (both in IDEA and on the CLI), and following all the usual "Invalidate Cache and Restart" issues.
Further, the import issue is listed in the Gradle build on the CLI so it doesn't seem isolated to IDEA.
What am I missing here?
Here's the build.gradle file produced by IDEA when I was creating the project initially, and which IDEA is using for project/workspace synchronization.
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.50'
}
group 'com.craigotis'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
apply plugin: 'antlr'
dependencies {
antlr "org.antlr:antlr4:4.5"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Try adding this to your build.gradle:
sourceSets {
main.java.srcDirs += "${project.buildDir}/generated-src/antlr/main"
}
generateGrammarSource {
arguments += ["-visitor", "-package", "com.craigotis.sprint.core.antlr"]
outputDirectory = file("${project.buildDir}/generated-src/antlr/main/com/craigotis/sprint/core/antlr")
}
compileKotlin.dependsOn generateGrammarSource
Shouldn't it locate the compiled classes and not the sources? Do you see the antlr generated classes in the target directory?
Try this: first build the project without referencing or using any ANTLR generated classes, and only after the build is successful, then add the code that references them.
(In other words, what I think that happens, is that your ANTLR sources are compiled after the code that references them. They never have a chance to compile because build fails before)
Also if this is really the case, you can solve it also by splitting into two artifacts and make sure the ANTLR one is built before the one with the code that uses it
Try to add generated sources in idea module like this post from Daniel Dekany here:
apply plugin: "idea"
...
sourceSets.main.java.srcDir new File(buildDir, 'generated/javacc')
idea {
module {
// Marks the already(!) added srcDir as "generated"
generatedSourceDirs += file('build/generated/javacc')
}
}

MoreTypes class not found

I have a java project that is using dagger-2 and grpc, when I try to build it using ./gradlew build I get the following error:
> java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
is MoreTypes supposed to be provided inside of dagger-2 dependencies or I should provide that dependency on the class path?
this is the relevant parts of gradle.build file content:
plugins {
id "net.ltgt.apt" version "0.10"
id "com.google.protobuf" version "0.8.1"
id "java"
}
dependencies {
compile 'io.grpc:grpc-all:1.5.0'
compile 'com.google.dagger:dagger:2.14'
apt 'com.google.dagger:dagger-compiler:2.14'
testApt 'com.google.dagger:dagger-compiler:2.14'
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
This is a problem in Dagger 2.14 fixed in 2.14.1. See issue 994, "Dagger 2.14 breaks build":
I have not isolated the issue to a small sample project at this point, but a possible cause I see is below, maybe that gives a pointer. I don't have any explicit dependency on Google Auto libs in that part of the build.
java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
Confirmed fixed in 2.14.1, which contains this commit.

Make IntelliJ resolve dependencies from modules in same project

Using IntelliJ 2016.2.5, I seem to be unable to make it resolve Gradle dependencies which are in the same project.
Project structure is as follows:
firstModule
-> build.gradle // 1
-> settings.gradle // 2
secondModule
-> build.gradle // 3
-> settings.gradle // 4
Contents of first build.gradle (1):
group 'de.test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {mavenCentral()}
dependencies {}
And settings.gradle (2):
rootProject.name = 'test'
The contents of the second build.gradle (4) are:
group 'de.test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {mavenCentral()}
dependencies {
compile ('de.test:test:1.0-SNAPSHOT')
}
And second settings.gradle (4):
rootProject.name = 'testdep'
Both modules are imported as Gradle projects and are set to auto-import enabled.
I know from maven projects, that IntelliJ - as well as Eclipse - does resolve those dependencies to the respective modules in the project/workspace. But with Gradle it seems to not recognize the dependencies. After every change in the module test I need to run the explicit gradle tasks clean and build before the module testdep seems to pick up the changes. And this process is not even reliable, if I don't change the version. This is most likely because of the gradle caching, but it is annoying, nevertheless.
Using the command line argument --refresh-dependencies is not a real solution because it makes the build times of our project (the one above is only for demo purposes) unbearable. Also, I would love to not having to use the gradle calls explicitly.
Any ideas/improvements how to handle such a situation?
Does it work with Eclipse, any experiences?
Will this be fixed in IntelliJ 2016.3 (I saw some improvements in the gradle area for that release).
What you are trying to do will be possible using the new Composite Builds functionality in Gradle. Support for IntelliJ IDEA is coming soon.

Is there a gradle plugin to package Java Webstart applications?

Is there a gradle plugin to package Java Webstart (JWS) applications, similar to what Maven webstart plugin does? I need to automate at least the following tasks:
jnlp descriptor generation based on an existing template, automatic adding project dependencies;
jar signing based on the files described on jnlp file or project dependencies;
As of Aug 2016, the answer is "no".
There is a plugin under development per #Jake's answer. But there is no turn key solution. You'll have to do the work yourself to create a webstart app in Gradle... either with your own custom solution or by contributing to the plugin mentioned until it works for you.
Here's the plugin direct link: https://github.com/tschulte/gradle-jnlp-plugin
Found the following link outside of Stack Overflow and looks like it does some of what you are looking for but not all. Hopefully this gets you closer to what you need...
This is an old post, but answering anyway.
I could configure gradle-jnlp-plugin.
Steps:
-Create an empty folder.
-Create src folder with Java code. I used the sample AccessibleScrollDemo.
-Copy keystore.ks from examples or create your own using genkey task in plug-in.
-Create build.gradle with following configuration.
The plug-in has examples of various options for jnlp task.
-Run plug-in task using gradle (v2.4 or more).
gradle createWebstartDir
-This will create the jnlp file under build directory, and also jars in build/lib.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.gliderpilot.gradle.jnlp:gradle-jnlp-plugin:+'
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'de.gliderpilot.jnlp'
group = 'misc'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenCentral()
}
mainClassName = 'misc.AccessibleScrollDemo'
sourceSets {
main.java.srcDir "src"
}
dependencies {
runtime('log4j:log4j:1.2.17') {
exclude group: 'ant', module: 'ant-nodeps'
exclude group: 'ant', module: 'ant-junit'
exclude group: 'ant-contrib', module: 'ant-contrib'
}
runtime 'org.slf4j:slf4j-log4j12:1.7.21'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
jnlp {
useVersions = false
usePack200 = false
withXml {
information {
title project.name
vendor project.group ?: project.name
}
security {
'all-permissions'()
}
}
signJarParams = [keystore: 'keystore.ks', alias: 'myalias', storepass: 'mystorepass']
}
compileGroovy.enabled = false
afterEvaluate {
// prevent ClassCastException
project.version = project.version.toString()
}
}
I think the Gradle JNLP Plugin currently registered in the Gradle Plugins directory may be the project for which you're looking.
Tobias Schulte's Gradle JNLP Plugin ( tschulte/gradle-jnlp-plugin on GitHub ) was striving for this about a year ago, but the new plugin is both registered in the Gradle Plugin site and looks to be under much more active development.

Categories