Troubleshooting common Maven issues | IntelliJ IDEA

文章推薦指數: 80 %
投票人數:10人

In some cases when you import a Maven project, it might have compiler settings that will not match the expected settings in IntelliJ IDEA ... TroubleshootingcommonMavenissuesIfyouencounterproblemsworkingwithyourMavenprojectyoucanchecktoseeifthefollowingsolutionsandworkaroundscanhelpyousolveyourissues.HowtofixcompilerversionproblemsinMavenprojectsInsomecaseswhenyouimportaMavenproject,itmighthavecompilersettingsthatwillnotmatchtheexpectedsettingsinIntelliJ IDEAandwhenyoucompileyourcode,youmightencounteraproblem.Forexample,youcangetthefollowingerror:Thiserrorusuallyindicatesaproblemwiththecompilerversioncompatibility,andyoucancheckfewplacestofixit.Forexample,youcanedityourPOMandconfigureMavencompilerplugintocompileyourJavacode.Youshouldsetthecompilerlevelexplicitly,soitwon'treverttothedefaultsettingswhenyoure-importyourproject.SetthecompilerlevelinPOMOpenyourPOMintheeditor.ChangetheconfigurationfortheMavencompilerplugin. org.apache.maven.plugins maven-compiler-plugin 3.7.0 1.8 1.8 UTF-8 Clicktoimportyourchanges.NotethattheconfigurationsspecifiedinyourPOMoverridesanyconfigurationsspecifiedinyourprojectstructure.So,nowafterthisprojectisimportedthelanguagelevelshouldbepickedup.ChecktheJavacompilersettingstoseeifthebytecodeversionsmatch.CheckthecompilersettingsIntheSettings/Preferencesdialog(Ctrl+Alt+S),gotoBuild,Execution,Deployment|Compiler|JavaCompiler.Onthepagethatopens,checkifProjectbytecodeversionandTargetbytecodeversionmatch,orleavetheTargetbytecodeversionoptionblanksoitcanbedeterminedfromJDK.Ifyouhaveimportedamulti-levelproject,youcancheckprojectstructuresettingsforsourcelanguagelevelconfiguration.CheckthelanguagelevelintheprojectstructureOpenProjectStructuredialogandselectProjectfromtheoptionsontheleft.Checkthesourcelanguagelevelforyourproject.Checkthesourcelanguagelevelforeachmodule(clicktheSourcestab).HowtofixproblemswithMavenprojectsthatwon'tstartTofixissuesthatarerelatedtotheMavenprojectsthatwon'tstartorimport,youcanperformoneofthefollowingactions.IfyoureceivedtheOutOfMemoryerror,trytoincreasetheheapsizefortheMavenimporter.IntheSettings/Preferencesdialog(Ctrl+Alt+S),gotoBuild,Execution,Deployment|BuildTools|Maven|Importing.YoucanclicktheiconintheMaventoolwindowtoopentheMavensettings.OntheImportingpage,intheVMoptionsforimporterfield,increaseheapsizefortheMavenimporter.Also,intheJDKforimporterfield,increaseIDEheapsize.Ifyouneedtousemoreheap,switchto64-bitJavaandspecifythesame64-bitJVMforMavenJDKforimporter.IfyoureceivedtheOperationtimedouterrororIDEconnectionfailuretotheMavenprocess,trytoeditthehostsfile.EditthehostsfileOnsomesystemsyouneedtoeditthehostsfilesothatlocalhostresolvescorrectly.Trytohave127.0.0.1localhostintheetc/hostsfile.Also,makesuretherearenootherIPaddressesmappedtolocalhost.IftheerrorindicatestheMavenrepositoryissue,suchastheFailedtoupdateMavenindiceserror,trytocheckifMavenrepositorieswereindexedcorrectly.IntelliJ IDEAworkswithrepositoryindexes.Theindexesarefetchedremotelyfromremoterepositories.Somerepositoriesdonotprovideindexes,ordonotkeepanupdatedindex,forexample,repositoriesfromBintray,inthiscaseyoucanignoretheerror.Ifyouhaveanindexedrepository,butstillgetaMavenrepositoryerror,checkthefollowingoptions:ChecktheusersettingsfileIntheSettings/Preferencesdialog(Ctrl+Alt+S),gotoBuild,Execution,Deployment|BuildTools|Maven.YoucanclicktheiconintheMaventoolwindowtoopentheMavensettings.OntheMavenpage,intheUsersettingsfilefield,checkifyoudefinedpropercredentialsfortheserverinsettings.xml.YoucantrytorestartIntelliJ IDEAandupdateMavenrepositories.UpdateMavenrepositoriesIntheSettings/Preferencesdialog(Ctrl+Alt+S),gotoBuild,Execution,Deployment|BuildTools|Maven|Repositories.YoucanclicktheiconintheMaventoolwindowtoopentheMavensettings.SelectRepositoriesfromoptionsontheleft.OntheRepositoriespage,clickUpdatetoupdateMavenrepositories.Aftertheupdateisfinished,clickOK.MavendependenciesimportedincorrectlyIfthedependenciesweren'timportedcorrectly(IntelliJ IDEAhighlightsthem),trytoperformthefollowingactions:YoucancheckyourlocalmavenrepositoryintheMaven|Repositoriessettingsandtrytoupdateit.Youcancheckthejarfileofthelocal.m2repositorytoseeifitwasdownloadedcorrectly.YoucanchecktheeffectivePOMtodeterminewhichMavenrepositorywasusedasanoriginofthedependency.YoucanselecttheAlwaysupdatesnapshotsoptioninMavensettings.Inthiscase,IntelliJ IDEAchecksthelatestversionofthedownloadeddependencyandupdatesitaccordingly.Lastmodified:17March2022AddMavensupporttoanexistingprojectGradle



請為這篇文章評分?