Could not find method application() for arguments
i tried gradle build but got this error
then i want to build the OneDrive client
i do not want to GET making a returnurl or get it by other means.
plugins {
id 'application'
}
application {
mainClassName = 'com.mycompany.app.App'
}
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src'
}
}
dependencies {
compile 'org.apache.httpcomponents:httpclient:4.5.10'
compile 'org.apache.httpcomponents:httpcore:4.4.12'
compile group: 'org.apache.httpcomponents', name: 'httpclient',
version: '4.5.10'
compile group: 'org.apache.httpcomponents', name: 'httpcore',
version: '4.4.12'
}
repositories {
jcenter()
maven {
url "https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient"
}
maven {
url
Related
I created spring-boot gradle multi-module project which consisted of 3 modules: controller, service, repository. Main file was situated in Controller-module and named MySpringBootApplication.
I could build this project (using gradle build) and could get jar-file. But after starting this jar in command line I took the next error:
Error: Could not find or load main class com.epam.esm.config.MySpringBootApplication Caused by: java.lang.ClassNotFoundException: com.epam.esm.config.MySpringBootApplication.
To fix this bug I added Main-Class attributte to MANIFEST.MF file in main build.gradle but this action didn't help. So could anybody help?
MAIN BUILD.GRADLE FILE
plugins {
id 'java'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.4.3'
id 'application'
}
group = 'com.myproject'
version = 'snapshot-1.0.0'
repositories {
mavenCentral()
}
bootJar {
enabled = false
}
jar {
enabled = true
manifest {
attributes(
"Main-Class": "com.myproject.config.MySpringBootApplication")
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.4.3', ext: 'pom'
}
test {
useJUnitPlatform()
}
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
group = 'com.epam.esm'
version = '1.0.0'
repositories {
mavenCentral()
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.hibernate', name: 'hibernate-envers', version: '5.4.27.Final'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'org.openidentityplatform.commons', name: 'json-web-token', version: '2.0.11'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.18'
annotationProcessor 'org.projectlombok:lombok'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.4.3', ext: 'pom'
}
test {
useJUnitPlatform()
}
}
SETTINGS.GRADLE
rootProject.name = 'module'
include('repository', 'service', 'controller')
The Spring Boot application executable jar file is built by bootJar task, so adding the main-class information via jar won't work either.
The bootJar task tries to create an executable jar, and that
requires a main() method. As a result, you need to disable the
bootJar task and enable the jar task (which creates an ordinary jar
rather than an executable jar) only for your no executable jar
modules.
Since you did it under subprojects section, the controller module will produce a standard jar as well. You may produce standard jars for all modules but excluding the controller module as follows:
subprojects {
if (it.name != 'controller') {
bootJar {
enabled = false
}
jar {
enabled = true
}
}
}
In addition you have to remove the jar section below
jar {
enabled = true
manifest {
attributes(
"Main-Class": "com.myproject.config.MySpringBootApplication")
}
}
and replace
bootJar {
enabled = false
}
with
bootJar {
mainClassName = 'com.myproject.config.MySpringBootApplication'
}
Reference
Creating a Multi Module Project
Running the IDEA IDE I want to add a gradle dependency for the jUnit v5.
Here is my build.gradle file, I used this answer as a guide.
apply plugin: 'java'
sourceCompatibility = 1.8
repositories { mavenCentral() }
apply plugin: 'org.junit.platform.gradle.plugin'
dependencies {
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
testRuntime("org.junit.vintage:junit-vintage-engine:4.12.0-M4")
testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0-M4")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0-M4")
// Enable use of the JUnitPlatform Runner within the IDE
testCompile("org.junit.platform:junit-platform-runner:1.0.0-M4")
compile ("org.junit.jupiter:junit-jupiter-api:5.0.0-M4")
}
sourceSets {
main {
java {
srcDir 'src'
}
}
}
junitPlatform {
details 'tree'
}
The problem here is that the jUnit4 annotations are resolved by import but all the v5 annotations are not resolved.
One example:
#ParameterizedTest
public void testExample() {
// My annotations is not resolved
}
What is the right way to add a jUnit5 dependency using gradle?
EDIT
I started a new gradle java project from scratch to get to the bottom of this.
Here is my current build.gradle.
group 'com.iay0361'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories { mavenCentral() }
apply plugin: 'org.junit.platform.gradle.plugin'
dependencies {
testCompile group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '4.12.0-RC3'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-RC3'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0-RC3'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.0.0-RC3'
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.0.0-RC3'
}
sourceSets {
main {
java {
srcDir 'src'
}
}
}
junitPlatform {
details 'tree'
}
I wrote the #Test annotation in a new class file under test after which it asked me to "add the 'jUnit5' to classpath
which I did and this time selected the Copy 'jUnit5' libraries to... instead of using the IDEA distributor.
Now it added these files in module:
The file is still RC2 but in build.gradle it is RC3.
There are also no jUnit jars in "External Library" directory
What am I missing, the problem is still that the IDE cannot resolve some jUnit5 annotations like #ParamiterizedTest.
Here is a quick sample on how to configure gradle with junit5. In your dependencies, remove the compile statement for the junit:4.12 artifact verison.
// If you also want to support JUnit 3 and JUnit 4 tests
testCompile("junit:junit:4.12")
In the buildscript() method, include these:
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3' }
}
I need to add jar generated from running application into same application classpath.
Flow - i have generated set of class files(packaged as jar) from WSDL using axis 2 from java .Now i need to access the .class file in generated jar on same java project.
I have used Build Tool Gradle
Here is my code , to build jar for generated set of java files.
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
sourceCompatibility = 1.8
bootRepackage {
enabled = false
}
sourceSets {
compile fileTree(dir:'C://Users//10Decoders//Downloads//axis2-1.7.4-bin//axis2-1.7.4//lib',include: '*.jar')
preBuildSources
main {
java {
srcDirs = ['../'+customProp]
println "sourceSets -- > DONE ---"+customProp
}
}
}
task copypackage(type: Copy){
println "COpy Jar to package - > "
into customProp
from customProp+'/src/'
}
jar {
archiveName = customProp+'.jar'
destinationDir = projectDir
println "JAR BUILD---- > "
}
}
task mydatafile(dependsOn:build){
println "COpy Jar to claspath - > "+customProp
doLast{
copy{
into "../"
from customProp+'.jar'
}
}
}
build.dependsOn copypackage
Another Gradle file to build jar for current java application(Which has main function)
Build.script 2
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
dependencies {
compile 'org.springframework:spring-support:2.0.8'
compile 'org.springframework:spring-aop:4.1.2.RELEASE'
compile 'org.springframework:spring-beans:4.1.2.RELEASE'
compile 'org.springframework:spring-context:4.1.2.RELEASE'
compile 'org.springframework:spring-core:4.1.2.RELEASE'
compile 'com.squareup.okio:okio:1.11.0'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'org.json:json:20160810'
compile 'mysql:mysql-connector-java:5.1.38'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile group: 'com.predic8', name: 'soa-model-core', version: '1.5.4'
// https://mvnrepository.com/artifact/wsdl4j/wsdl4j
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
// https://mvnrepository.com/artifact/org.reflections/reflections
compile group: 'org.reflections', name: 'reflections', version: '0.9.5-RC2'
}
jar {
archiveName = 'batch.jar'
destinationDir = projectDir
manifest {
attributes (
'Main-Class': 'com.wsdl.migration.SpringWsdlFieldIdentification',
'Class-Path': 'testAPP.jar mydata/'+customProp+'.jar'
)
}
}
task copyLibs(type: Copy){
println "buildDir- > "+buildDir
}
build.dependsOn copyLibs
Here customProp is variable to get the jar name dynamically while run the gradle build.(gradle build -P customProp=XXXXtask ).
BottomLine : I cannot able to access the classes from the dynamically generate jar.So the Question becomes - How can i add the jar file into running application on runtime??.Thanks in advance.
I am attempting to create a project with Gradle, when I run individual tests I get this error.
Information:26/10/16 11:22 - Compilation completed with 1 error and 0
warnings in 158ms Error:gradle-resources-test:Sunday-Sessions_test:
java.lang.NoSuchMethodError:
org.gradle.api.specs.AndSpec.getSpecsArray()[Lorg/gradle/api/specs/Spec;
I have tried refreshing the gradle project and have also done file->invalidate caches and restart, this has not helped. Here is my gradle file, can anyone see why this is happening?
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.3.3"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
}
}
ext {
// The drivers we want to use
drivers = ["chrome", "phantomJs"]
ext {
gebVersion = '0.13.1'
seleniumVersion = '2.52.0'
chromeDriverVersion = '2.19'
phantomJsVersion = '1.9.7'
}
}
apply plugin: "io.ratpack.ratpack-groovy"
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "idea"
apply plugin: "eclipse"
repositories {
jcenter()
}
dependencies {
// Default SLF4J binding. Note that this is a blocking implementation.
// See here for a non blocking appender http://logging.apache.org/log4j/2.x/manual/async.html
runtime 'org.slf4j:slf4j-simple:1.7.12'
// If using Spock, need to depend on geb-spock
testCompile("org.gebish:geb-spock:$gebVersion") {
exclude group: 'org.codehaus.groovy'
}
testCompile("org.spockframework:spock-core:1.0-groovy-2.4") {
exclude group: "org.codehaus.groovy"
}
// If using JUnit, need to depend on geb-junit (3 or 4)
testCompile("org.gebish:geb-junit4:$gebVersion") {
exclude group: "org.codehaus.groovy"
}
// http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.52.0'
compile "org.shamdata:sham:0.3"
// Drivers
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
// using a custom version of phantomjs driver for now as the original one does not support WebDriver > 2.43.1
testCompile("com.codeborne:phantomjsdriver:1.2.1") {
// phantomjs driver pulls in a different selenium version
transitive = false
}
testCompile('io.ratpack:ratpack-remote-test:1.3.0') {
exclude group: "org.codehaus.groovy"
}
// http://mvnrepository.com/artifact/com.google.inject/guice
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile 'io.ratpack:ratpack-handlebars:1.2.0'
compile 'com.fasterxml.jackson:jackson-parent:2.7-1'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
compile 'org.codehaus.groovy:groovy-all:2.4.4'
testCompile ratpack.dependency('test')
compile ratpack.dependency("remote")
testCompile ratpack.dependency("remote-test")
compile ratpack.dependency("hikari")
// https://mvnrepository.com/artifact/com.restfb/restfb
compile group: 'com.restfb', name: 'restfb', version: '1.26.0'
//Grab the user location with GeoIP2
compile 'com.maxmind.geoip2:geoip2:2.8.0-rc1'
}
When I run refresh gradle in IntelliJ IDEA, my main folder is set to be the source root, but "java", which is my actual source root, is unmarked.
I have to change this manually every time after I do gradle refresh.
Do you know what the relevant gradle setting is?
Can it be in a common gradle file?
Should I change the main folder to be the source root?
How can I know where is the common gradle I might inherit from?
How can I override this in my local build.gradle?
My build.gradle:
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
//
// configurations.all*.exclude(group: 'com.sun.jersey', module: 'jersey-bundle')
// configurations.all*.exclude(group: 'com.fasterxml.jackson.core', module:'jackson-databind')
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'com.google.inject:guice:4.0-beta5'
compile 'com.sun.jersey:jersey-core:1.18.3'
compile 'com.sun.jersey:jersey-client:1.18.3'
compile 'com.sun.jersey:jersey-json:1.18.3'
compile 'com.sun.jersey.contribs:jersey-apache-client:1.18.3'
compile group: 'junit', name: 'junit', version: '4.11'
compile 'com.vividsolutions:jts:1.13'
compile 'net.sf.opencsv:opencsv:2.3'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'com.google.guava:guava:18.0'
//testCompile group: 'junit', name: 'junit', version: '4.11'
}
sourceSets {
main {
java {
srcDirs = ['src/main']
}
}
test {
java {
srcDirs = ['src/main']
}
}
}
test {
testLogging {
// Show that tests are run in the command-line output
events 'started', 'passed'
}
}
task run_BaselineGenerator(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main = "com.waze.routing.automation.runners.BaselineGenerator"
}
Your sourceSets look incorrect to me. I would try:
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
}
test {
java {
srcDirs = ['src/test/java']
}
}
}