Search code examples
kotlinmavenintellij-idea

I cannot find local .jar files in .m2 directory


I want to make a local repository using publishToMavenLocal but after I using this command (even though with built-in button in IntelliJ IDEA IDE), I still cannot find the final directory (test): ".m2/com/test"

This is my build.gradle.kts file:

plugins {
    kotlin("jvm") version "1.9.23"
    id("maven-publish")
}

group = "com.test"
version = "0.1-SNAPSHOT"

What I have checked?

  • I have built the project.
  • Double check the directory name.
  • after adding kts("maven-publish"), I loaded Gradle changes.
  • Using terminal to run "publishToMavenLocal" and also IDE built-in button
  • I have checked if the local Maven repository is changed or not, so it is the default one: (User/.m2/)

The messages after running "publishToMavenLocal":

2:47:56 PM: Executing 'publishToMavenLocal'...

Task :publishToMavenLocal UP-TO-DATE

BUILD SUCCESSFUL in 2s

2:47:58 PM: Execution finished 'publishToMavenLocal'.

Do you have any suggestions?


Solution

  • The problem was due to the lack of below 'publishing' section and kotlin id("java-library") plugin in the project build.gradle.kts file.
    After adding the mentioned lines of code, another build command will be added to your gradle tab, which is called "publishLibraryNamePublicationToMavenLocal":

    plugins {
        kotlin("jvm") version "1.9.23"
        id("java-library")
        id("maven-publish")
    }
    
    group = "com.test"
    version = "0.1-SNAPSHOT"
    
    publishing {
        publications {
            create<MavenPublication>("[LIBRARY_NAME]") {
                from(components["kotlin"])
            }
        }
    }
    

    I have used this link from Gradle documentation to find my answer.