Share POJO Entity Data Classes between Android and Spring Projects

How can I reference, add, bind, depend on Java classes defined in another project or library without copying / pasting?

For:

  • Android Studio
  • IntelliJ IDEA
+4
source share
2 answers

Android Studio

AndroidProjectRoot / settings.gradle

Before

include ':app'

After

include ':app', ':common'
project(':common').projectDir = new File('../common')

AndroidProjectRoot / app / build.gradle

Before

apply plugin: 'com.android.application'
android {
  ...
}

dependencies {
}

After

apply plugin: 'com.android.application'
android {
  ...
}

dependencies {
    compile project(':common')
}

THEN ...

  • Tools -> Android -> project synchronization with Gradle files

Allows an Android Studio project to reference an external project (at the same directory level as AndroidProjectRoot /, without making a copy of the Java library inside your Android project.

Library project / module

build.gradle /. . , , ( ), , DAO, OrmLite.

Root/build.gradle

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-jdbc:4.48'
}

IntelliJ IDEA

  • β†’
  • ( ) ""
  • ( , ) +
  • , Java, . (. ).
  • ""

,

  • ( , ) ( , )
  • ( , ) +
  • 3 Dependency ...
  • (, )
  • ""
  • "" ( )
  • IDEA Gradle ( )

:

:

/
/build.gradle
/
/SRC/Java
/SRC/Java/
/SRC/Java//
/SRC/Java///
/SRC/Java////
common/src/java/main/com/your/package/YourClass.java

Mathias Hauser - Spring JPA

+3

pojo android:

, , , " ", " ", , . .

import, (, public)

0

Source: https://habr.com/ru/post/1599114/


All Articles