Gradle Unable to retrieve local repository - gradle

I have the following setup in my build.gradle file
repositories {
mavenCentral()
mavenLocal()
maven {
url '/Users/me/.m2/repository'
}
A library under the directory doesn't get imported into my project. I create another project with Maven and the library is imported. What is missing in the gradle setup?
Here is the file:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
mavenLocal()
maven {
url '/Users/vewu/.m2/repository'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'sample'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal() // <-- I need to add this one
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-stream-kafka')
compile('org.springframework.boot:spring-boot-starter-integration')
compile 'mylibrary:mypackage:1.3.18'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
}
}
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'
}
}
I just recognize that I need to add mavenLocal() on the repository block outside of the buildscript as well.

Related

Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

A problem occurred evaluating root project when adding allprojects{}.
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
Here is the code in build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
For Android Studio Arctic Fox |2020.3.1
Remove this from the build.gradle
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Go to settings.gradle and add follwing line
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
For Spring Boot gradle project this one of the ways by which you can specify build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url can be given like this "https://plugins.gradle.org/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
}
Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

How to configure 'mainClassName' for Spring Boot Application in a Kotlin Gradle multi-module project?

I have a Gradle multi-module project in Kotlin using Spring Boot in some of the modules.
I use the 'org.springframework.boot' and 'io.spring.dependency-management' plugin in the project's root build.gradle which besides other things provide the bootRun task.
AFAIK I need to configure the mainClassName (or entry point) like this:
springBoot {
mainClassName = 'de.shinythings.hexagon.HexagonApplicationKt'
}
While this works in the subproject that contains the actual Spring Boot application it does not work in the root project.
I want to be able to configure it in the root project because I want to be able to run my project with ./gradlew bootRun instead of ./gradlew configuration:bootRun.
Other tasks like ./gradlew build or ./gradlew test work fine.
Here is the root project's build.gradle (link):
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
implementation project(':configuration')
}
springBoot {
mainClassName = 'de.shinythings.hexagon.HexagonApplicationKt'
}
subprojects {
group = 'de.shinythings.hexagon'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
mockKVersion = '1.10.2'
}
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
dependencyManagement {
imports {
mavenBom('org.springframework.boot:spring-boot-dependencies:2.3.4.RELEASE')
}
}
compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
freeCompilerArgs = ["-Xjsr305=strict"]
allWarningsAsErrors = true
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
freeCompilerArgs = ["-Xjsr305=strict"]
allWarningsAsErrors = true
}
}
}
In the subproject/module this setting works (link) :
plugins {
id 'org.springframework.boot'
id 'org.jetbrains.kotlin.plugin.spring' version '1.4.10'
}
dependencies {
implementation project(':common')
implementation project(':application')
implementation project(':adapters:persistence')
implementation project(':adapters:web')
implementation 'org.springframework.boot:spring-boot-starter'
implementation('com.h2database:h2')
}
springBoot {
mainClassName = 'de.shinythings.hexagon.HexagonApplicationKt'
}
What do I have to do to configure the mainClassName is the root's project build.gradle?

Test function in Kotlin cannot find function in main module

I have a standard (multi-)project set-up in Kotlin using gradle, where I have a /src/main/kotlin/ and a /src/test/kotlin/.
I have a function in my main module that I would like to test, but when i create a test function in the same named directory in the test module, the function I wish to test isn't found and is not callable.
For reference, the root build.gradle
ext.kotlin_version='1.3.61'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
implementation "org.nd4j:nd4j-native-platform:1.0.0-beta5"
implementation "org.apache.commons:commons-lang3:3.9"
implementation "org.apache.commons:commons-math4"
implementation "io.ktor:ktor-server-core:1.2.6"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.3'
languageVersion = '1.3'
}
}
}
and the sub-project build.gradle:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.nd4j:nd4j-native-platform"
implementation "org.apache.commons:commons-lang3"
implementation "org.apache.commons:commons-math4"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Any help would be greatly appreciated

Ktor startup example errors

I'm very new to Kotlin and Ktor and Gradle, wanted to try Ktor, so gone through the steps explained here, and ended up with this code, and structure shown in the screenshot:
As seen there are lots of error, how to fix them?
package blog
import org.jetbrains.ktor.netty.*
import org.jetbrains.ktor.routing.*
import org.jetbrains.ktor.application.*
import org.jetbrains.ktor.host.*
import org.jetbrains.ktor.http.*
import org.jetbrains.ktor.response.*
fun main(args: Array<String>) {
embeddedServer(Netty, 8080) {
routing {
get("/") {
call.respondText("My Example Blog", ContentType.Text.Html)
}
}
}.start(wait = true)
}
The build.gradle file is auto generated as:
group 'Example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
You have incomplete build.gradle script (missing dependencies) - see here for details. Here's the good one:
group 'Example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
ext.ktor_version = '0.4.0'
repositories {
mavenCentral()
maven { url "http://dl.bintray.com/kotlin/ktor" }
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.ktor:ktor-core:$ktor_version"
compile "org.jetbrains.ktor:ktor-netty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.1"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
I would recommend using the IntelliJ Ktor plugin to bootstrap your app. The ./gradlew run script runs right out of the box with this configuration without you needing to fiddle with the Gradle configuration. It's the easiest way to get started.
Here is an example Ktor app that uses the configuration: https://gitlab.com/tinacious/ktor-example
If you'd like to run your application from IntelliJ, check out this answer for the run configuration I use: https://stackoverflow.com/a/65350680/1870884

spring boot war deployment to tomcat with status:OK But gives 404 on access

My configration class looks as follow
#Configuration
#EnableAutoConfiguration
#ComponentScan(basePackages = "com.projectx")
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Also build.gradle file looks like this
apply plugin: 'java'
sourceCompatibility=1.8
targetCompatibility=1.8
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
mainClassName = 'com.projectx.data.config.Application'
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
}
}
war {
baseName = 'gs-accessing-data-jpa'
version = '0.1.0'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/libs-release" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
So wherever i am deploying this project to tomcat it is showing following error. As I have mate all requirement to convert jar to war in spring not sure what is wrong this my project.
It gives 404 NOT FOUND.(I am using STS 3.6.0 with Gradle plugin)

Resources