Open francis-pang opened 3 years ago
Hi @francis-pang ,
I tried to re-produce the issue you mentioned, but I ended up having other problems related to maven compiler plugin. After fixing those, the build process for maven completed successfully, but SAM build fails because there were no target/classes
directory in the end.
And looking at the template file, CodeUri is pointing to 2 folders up (../../
) for the code base of the lambda function. If you have shared dependency I would suggest to publish those packages as another dependency for your lambda function, or use layers.
Please let us know if you have further issues.
@mndeveci , I tried to build based on the root folder, in which the template looks as below (partially):
Resources:
GetDiscrepantExpensesFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
Description: 'Retrieve all the mismatching transactions'
CodeUri: .
However it fails:
Running workflow 'JavaMavenWorkflow' Running JavaMavenWorkflow:CopySource JavaMavenWorkflow:CopySource succeeded Running JavaMavenWorkflow:MavenBuild Maven logs: [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for tally.expense:aws-lambda-get-expenses:49-SNAPSHOT: Could not find artifact tally.expense:aws-lambda:pom:49-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project tally.expense:aws-lambda-get-expenses:49-SNAPSHOT (/tmp/tmpgjbfjznj/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for tally.expense:aws-lambda-get-expenses:49-SNAPSHOT: Could not find artifact tally.expense:aws-lambda:pom:49-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
I found out that the SAM build command copy all the content which the template.yaml is located into a directory inside /tmp/. However it does not copy the root directory, where the parent pom resides. Due to this lack of dependency, the build fails.
Is it a technical restriction that there cannot be parent pom dependency in SAM application pom file?
@francis-pang ,
I would suggest to move all source files of your lambda function under another folder. So your root folder will look like this;
.
├── YourFunctionCode
│ ├── pom.xml
│ └── src
│ ├── main
│ │ └── java
│ │ └── ...
│ └── test
│ └── java
│ └── ...
└── template.yaml
And if you have dependencies of other projects, I would rather put them into a repository so that build can pull them, or create Lambda Layer(s) to share common code between different functions.
Closing. Feel free to reopen if there is further issue.
from my POV this poses a major restriction on developing SAM with java, we cannot use a parent pom which holds common definitions for plugins and build life cycle not to mention be able to have shared dependencies (because after all they would have to be in a sibling folder, and we can't use layers because sam doesn't build those autoamtically (it would if we could have used reactor builds, that would build that dependency first
...which are the bread and butter of developers who cleanly architect their code into multiple modules, and don't want to waste time mvn installing or (worse) releasing artifacts just to be able to deploy a serverless function during local development.
the sam build
command mvn install
s all modules to my local .m2 repostory which I go to great pains to kee free of manually
mvn install
ed dependencies.
the --debug
flag does not output what is actually going on
/tmp
, wait, what? debug output should include copying /blah/** to /tmp/blah...
so I can troubleshoot more easily what's going on, and then bug you about the next invalid assumption in your maven support.the poster is advised to change his project structure from a perfectly valid maven project structure, and then the issue is closed. How does that fix the problem? In order to show how the structure you impose on project structure is totally arbitrary, I expanded the generated java11 maven hello-world from sam cli with a second identical helloworld function, and added a 3rd top-level shared code module.
$ java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment Corretto-11.0.7.10.1 (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.7.10.1 (build 11.0.7+10-LTS, mixed mode)
$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/lestephane/.sdkman/candidates/maven/current
Java version: 11.0.7, vendor: Amazon.com Inc., runtime: /home/lestephane/.jdks/corretto-11.0.7
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-133-generic", arch: "amd64", family: "unix"
$ sam --version
SAM CLI, version 1.18.0
$ rm -rv ~/.m2/repository/helloworld/
$ git clone https://github.com/lestephane/sam-java11-maven-multimodule-app.git && sam-java11-maven-multimodule-app
$ mvn compile
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for HelloWorldParent 1.0:
[INFO]
[INFO] HelloWorldShared ................................... SUCCESS [ 0.415 s]
[INFO] HelloWorld ......................................... SUCCESS [ 0.011 s]
[INFO] HelloWorld2 ........................................ SUCCESS [ 0.008 s]
[INFO] HelloWorldParent ................................... SUCCESS [ 0.001 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
$ sam build
Building codeuri: HelloWorldFunction runtime: java11 metadata: {} functions: ['HelloWorldFunction']
Running JavaMavenWorkflow:CopySource
Running JavaMavenWorkflow:MavenBuild
Build Failed
Error: JavaMavenWorkflow:MavenBuild - Maven Failed: [INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< helloworld:HelloWorld >------------------------
[INFO] Building HelloWorld 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for helloworld:HelloWorldShared:jar:1.0 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/helloworld/HelloWorldShared/1.0/HelloWorldShared-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.809 s
[INFO] Finished at: 2021-02-11T16:04:33+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project HelloWorld: Could not resolve dependencies for project helloworld:HelloWorld:jar:1.0: Could not find artifact helloworld:HelloWorldShared:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The multi-module maven support is poor in SAM CLI. Please take it seriously.
problem still exists.
Error: JavaMavenWorkflow:MavenBuild - Maven Failed: [INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for cn.hashdata:key-center-lambda-function:1.0-SNAPSHOT: Could not find artifact cn.hashdata:cloud:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project cn.hashdata:key-center-lambda-function:1.0-SNAPSHOT (/private/var/folders/l9/lc7d0t_97r7b38pmbl_3h8nc0000gn/T/tmpj4x4vykc/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for cn.hashdata:key-center-lambda-function:1.0-SNAPSHOT: Could not find artifact cn.hashdata:cloud:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
SAM Build has failed: Command did not exit successfully, exit code: 1
KeyCenterFunction has failed: Command did not exit successfully, exit code: 1
@mndeveci could you please help with this? Multi-module maven support is poor.
@pengfeiwang-cn can you give an example template that we can use to re-produce the issue that you are facing?
First message in this thread has this example (git@github.com:francis-pang/expense-tally.git), is yours same as that one?
Following
Found a workaround but this is still painfull... 👍 for this feature to be implemented.
the workaround:
from-parent-pom$ mvn install
it will copy the parent-pom in ~/.m2/...
then sam build
will work
Description
I faced an build issue when I build the serverless application on my local machine. The pom error show
However, this is not a maven issue, because I am able to build my project successfully manually with the maven command.
Steps to reproduce
sam build --use-container --template-file template.yaml
Observed result
Expected result
It is expected that the build will be successful. An execution of the successful run via maven command is uploaded to pastebin:https://pastebin.pl/view/0408a9f8
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS Name Microsoft Windows 10 Pro Version 10.0.19041 Build 19041 Execute this on WSL: WSL build: 4.4.0-19041-Microsoft #488-Microsoft Mon Sep 01 13:43:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
WSL Distribution information Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal
Java version: 11 Maven version: 3.6
sam --version
: 1.4.0