Question

Most of the configurations that I have seen for using Gradle + Spring-data-neo4j + Aspectj have been either for Eclipse and/or using Maven. I can't seen to find a complete setup to get to work properly.

Here's is my build.gradle:

apply plugin:'base'
apply plugin:'java'
apply plugin:'idea'

buildscript {
    repositories {
        maven {
            url "https://maven.eveoh.nl/content/repositories/releases"
        }
    }
    dependencies {
        classpath "nl.eveoh:gradle-aspectj:1.4"
    }
}

repositories {
    maven {
        url "http://m2.neo4j.org/content/repositories/releases/"
    }
    mavenCentral()
    mavenLocal()
}

project.ext {
    springVersion = "4.0.3.RELEASE"
    neo4jVersion = "2.0.1.RELEASE"
    springDataGraphVersion = "3.0.1.RELEASE"
    aspectjVersion = "1.7.4"

    sourceCompatibility = 1.7
    targetCompatibility = 1.7
}

apply plugin: 'aspectj'

compileAspect {
    xlint = 'warning'
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.6'

    compile "org.springframework:spring-context:${springVersion}"
    compile "org.neo4j:neo4j:${neo4jVersion}"
    // Provides Repository based Object <-> Graph Mapping
    compile "javax.validation:validation-api:1.0.0.GA"
    compile "org.springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}"
    compile 'javax.persistence:persistence-api:1.0-rev-1'


    testCompile 'junit:junit-dep:4.11'
    testCompile "org.springframework:spring-test:${springVersion}"
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    // Access to Neo4j testing facilities: TestGraphDatabaseFactory
    testCompile "org.neo4j:neo4j-kernel:${neo4jVersion}:tests@jar"
    testRuntime 'org.slf4j:slf4j-simple:1.7.5'

    //aspectj dependencies
    aspectpath "org.aspectj:aspectjtools:${aspectjVersion}"
    compile "org.aspectj:aspectjrt:${aspectjVersion}"
    aspectpath group: "org.springframework.data", name: "spring-data-neo4j", version: springDataGraphVersion
}

configurations {
    runtime
    compileJava
    testCompileJava
}

// Generate wrapper for Gradle
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

The current documentation doesn't seem to have the Aspectj gradle information in it. I used the info from the 2.3.5.RELEASE which I've merged into this build. I have also set ajc for the compiler but I still think something is missing since that is old. Also, I am NOT using pom.xml but the Java configuration file which is below.

@Configuration
@ComponentScan(basePackages = "domains")
@EnableNeo4jRepositories(basePackages = "repos")
//@EnableSpringConfigured
@EnableTransactionManagement
public class AppConfigTest extends Neo4jAspectConfiguration {

    public AppConfigTest () {
        setBasePackage("domains");
    }

    @Bean (destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() {
        return new TestGraphDatabaseFactory().newImpermanentDatabase();
    }

}

==============[EDIT 1]=================

Updated Gradle build file above using the project eveoh/gradle-aspectj as noted by @StefanArmbruster below. However, now I get this error:

* Where:
Build file 'build.gradle' line: 52
> Could not find method aspectpath() for arguments [org.aspectj:aspectjtools:1.7.4] on root project

==============[EDIT 2]=================

Updated Gradle build fixing the issue above for the moment but now I have this issue:

10:44:10 AM: Executing external task 'build'...
:processResources UP-TO-DATE
:compileAspect FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileAspect'.
> Error creating temporary file

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 42.556 secs
Permission denied
10:44:53 AM: External task execution finished 'build'.
Was it helpful?

Solution

Finally got this to work (at least this part of it). Final build.gradle:

apply plugin:'base'
apply plugin:'java'
apply plugin:'idea'

buildscript {
    repositories {
        maven {
            url "https://maven.eveoh.nl/content/repositories/releases"
        }
    }
    dependencies {
        classpath "nl.eveoh:gradle-aspectj:1.4"
    }
}

repositories {
    maven {
        url "http://m2.neo4j.org/content/repositories/releases/"
    }
    mavenCentral()
    mavenLocal()
}

project.ext {
    springVersion = "4.0.3.RELEASE"
    neo4jVersion = "2.0.1.RELEASE"
    springDataGraphVersion = "3.0.1.RELEASE"
    aspectjVersion = "1.7.4"

    sourceCompatibility = 1.7
    targetCompatibility = 1.7
}

apply plugin: 'aspectj'

compileAspect {
    xlint = 'warning'
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.6'

    compile "org.springframework:spring-context:${springVersion}"
    compile "org.neo4j:neo4j:${neo4jVersion}"
    // Provides Repository based Object <-> Graph Mapping
    compile "javax.validation:validation-api:1.0.0.GA"
    compile "org.springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}"
    compile 'javax.persistence:persistence-api:1.0-rev-1'


    testCompile 'junit:junit-dep:4.11'
    testCompile "org.springframework:spring-test:${springVersion}"
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    // Access to Neo4j testing facilities: TestGraphDatabaseFactory
    testCompile "org.neo4j:neo4j-kernel:${neo4jVersion}:tests@jar"
    testRuntime 'org.slf4j:slf4j-simple:1.7.5'

    //aspectj dependencies
    aspectpath "org.aspectj:aspectjtools:${aspectjVersion}"
    compile "org.aspectj:aspectjrt:${aspectjVersion}"
    aspectpath group: "org.springframework.data", name: "spring-data-neo4j", version: springDataGraphVersion
}

configurations {
    runtime
    compileJava
    testCompileJava
}

// Generate wrapper for Gradle
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

The placement of the buildscript, extra properties, and the apply plugin 'aspectj' matters. I got to fooling around with which order I needed and I have this.

I still don't have weaving properly I think, however, but that's a different topic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top